-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathHA-Roller.yaml
More file actions
910 lines (863 loc) · 35 KB
/
HA-Roller.yaml
File metadata and controls
910 lines (863 loc) · 35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
# REALiAM: https://github.com/R34LiAM/HA-Roller
# Heavily inspried by PeterG: https://www.thingiverse.com/pgote/designs
# And RoadkillUK: https://github.com/RoadkillUK/Motor-on-a-Roller-Blind-for-ESPHOME
# Tested on ESPHome Device Builder 2025.3.0 but will probably work fine on later revisions
# All that needs to be changed before compiling and flashing is in the 'substitutions:' section below.
# you may need to change the 'esp8266:' section as well depending on what board and model you use...
# Once the ESP has booted for the first time it's time for configuration
# The easiest way, if using Home Assistant, is to use the yaml-code in the card from this repo.
# OR access the webGUI at <coverip>:80 or <hostname>.local:80 if you have mDNS, or use a hardwired button to configure it.
# I recommend wiring a button so the roller can be controlled "manually" at the window, See setup option 2 below.
# If no button is wired see setup option 1 or 3 below for setup using Home Assistant or the webGUI.
# Setup option 1 (Easiest)
#-----------------------------
# Add the yaml-code from this repo to your Home Assistant dashboard.
# 1) Expand the 'Setup, Settings and Parameters' section in the card and click 'Activate Setup'.
# 2) Follow the on screen instructions...
# Repeat from step 1 if you need to reconfigure in the future.
# Setup option 2 (Recommended)
#-----------------------------
# This sketch also includes support for a momentary button wired to the substitute value of 'pinButton' below, which can be used in the following way:
# 1) Press button for > 4 seconds and then release, to enter setup mode.
# 2) Press button again to start closing the blind.
# 3) Once the position you want as 100% closed (fully closed) is reached, press the button.
# The blind will instantly start to open again (actually resets the stepper position to 0)
# 4) Once the position you want as 100% open (fully open) is reached, press the button.
# 5) Done.
# The button loops through states as: open/stop/close/stop/open....... once configured.
# Repeat from step 1 if you need to reconfigure in the future.
# Setup option 3
#---------------
# 1) Turn on the 'Activate Setup' Switch to enter setup mode.
# 2) Press Action button to start the blind closing.
# 3) Press Action button again when closed and blind starts to open. (actually resets the stepper position to 0)
# 4) Press Action button again when blind is fully open.
# 5) Done.
# Add to your frontend of choice.
# Home Assistant using the ESPHome API integration or MQTT.
# HomeKit using Homebridge and mqttthing or via Home Assistant's HomeKit integration.
# And more...
# What has been changed added?!
# Added some extra sensors that report back to Home Assistant since they are availiable for free (uptime / reset button / wifi signal and so on)
# Added support for stopping while moving up and down and start moving in the reverse direction using just one button
# Added ability to choose wether ESP should report back to Home Assistant continuously or only when it has reached the set position (combined the functionallity of RoadkillUK's two seperate scripts)
# Removed 'Silent Drive Mode' option, since the stepper speed can now be easily adjusted at runtime
# Added ability to "adjust" stepper speed, perfect for automations that run late at night when more quiet operation is preferred over speed. (for a 28byj-48 5v stepper motor a value of 600-700 steps/s works well)
# Added visual cue, the onboard LED of the Wemos D1 mini lights up (blue) to indicate when in setup mode, might need "allow_other_uses: true" for older designs
# Rearranged a whole lot to make it easier to change needed parameters
# Pretty much everything is customized in the "substitutions"-section below.
# If not using a "secrets"-file (which I recommend) you also have to change:
# !secret ota_password
# !secret wifi_ssid
# !secret wifi_password
# !secret api_password
# !secret ap_fallback_wifi_password
##########################################################
##########################################################
# CONTROL USING MQTT TOPICS
##########################################################
##########################################################
# The topics change according to your [hostname] defined
# under the substitutions section below. Example below
# is with hostname set to "rullgardin01"
# MQTT needs to be activated and configured below
#
# For current position, subscribe to the following topic:
# rullgardin01/cover/rullgardin01_roller/position/state
#
# To set position, publish to the following topic: (0-100, 0=close, 100=open)
# rullgardin01/cover/rullgardin01_roller/position/command
#
# To stop, closing or opening, publish the current position to the following topic:
# rullgardin01/cover/rullgardin01_roller/position/command
#
# To set "Continuous feedback switch", (ON/OFF) publish to the following topic:
# rullgardin01/switch/rullgardin01_continuous_feedback/command
# rullgardin01/switch/rullgardin01_continuous_feedback/command
#
# To Reboot ESP, publish (ON) to the following topic:
# rullgardin01/switch/rullgardin01_restart/command
#
##########################################################
##########################################################
# CONTROL USING POST TO REST API
##########################################################
##########################################################
# The calls change according to your [hostname] defined
# under the substitutions section below. Example below
# is with hostname set to "rullgardin01".
# Works with IP instead of .local if you don't use mDNS/Multicast
#
# Using POST you can control it using the following URL's
# Open:
# http://rullgardin01.local/cover/rullgardin01_roller/open
#
# Close:
# http://rullgardin01.local/cover/rullgardin01_roller/close
#
# Stop current operation (while opening or closing):
# http://rullgardin01.local/cover/rullgardin01_roller/stop
#
# Set position:
# fully closed:
# http://rullgardin01.local/cover/rullgardin01_roller/set?position=0.0
# fully open:
# http://rullgardin01.local/cover/rullgardin01_roller/set?position=1.0
# halfway open/closed:
# http://rullgardin01.local/cover/rullgardin01_roller/set?position=0.5
# And so on...
# Wemos D1 mini pin/GPIO layout
# D0 = GPIO16
# D1 = GPIO5
# D2 = GPIO4
# D3 = GPIO0
# D4 = GPIO2 (internal LED, don't use or add "allow_other_uses: true" might work)
# D5 = GPIO14
# D6 = GPIO12
# D7 = GPIO13
# D8 = GPIO15
# TX = GPIO1
# RX = GPIO3
# A0 = ADC0
## Substitutions
substitutions:
sub_hostname: 'rullgardin01' # hostname/devicename/esphome sensors (keep lcase)
sub_friendly_name: 'Kontor fönster' # More easily identify you roller
coverip: '192.168.0.150' # Static IP
covergateway: '192.168.0.1'
coversubnet: '255.255.255.0'
speed: '700' # Default value, as an example, steps/s (speed) of the motor set to a value between 600-700 is usually ok for operating a "fridans" of 140 cm in width...
speedsteps: '50' # With what value should the step/s (speed) increase/decrease when configuring.
minspeed: '100' # What value could be set as the minimum step/s (speed).
maxspeed: '1000' # What value could be set as the maximum step/s (speed).
## specify your mqtt-broker ip, uncomment to use and don't forget to uncomment the "MQTT:" section below as well
#mqtt_broker_ip: '192.168.0.211'
mystepper: my_stepper # Name of the stepper motor (leave as is) everythings breaks if you do.
delaybetweenupdates: 500 ms # Milliseconds between updates being pushed to Home Assistant ESPHome API
## Uncomment pinSLP, pinSTP and pinDIR for the microcontroller you are using
## If you have conflicts between pins this might help: "allow_other_uses: true"
# ****** New PCB ****** use below and uncomment "Legacy PCB"-section
## Wemos d1 mini
#pinPIR: D7 # PIR (Passive IR sensor) pin
#pinIRSend: D5 # Playback IR signals from MQTT topic
pinButton: GPIO1 #TX # physical button to controll the roller blind (up/stop/down/stop/up.......) (hold for +5 seconds to enter setup mode/press once to start closing, press again at maximum-/bottom position, lastly press at minimum-/top position)
pinReedSwitch: GPIO12 #D6 # Used for window open/closed, a reed(magnetic) sensor
#pinXtra: # Might be used for something of your choice
pinDIR: GPIO0 # DIRECTION > A4988
pinSTP: GPIO4 # STEP > A4988
pinSLP: GPIO5 # SLEEP & RESET > A4988
pinDIRReversed: 'false' # Change to true if roller blind goes up instead of down and vice versa (reverse direction)
pinLED: GPIO2 # Used for the Wemos on board LED to indicate when in "setup-mode"/LED on
# ****** Legacy PCB ****** use below and uncomment "New PCB"-section (be sure to also uncomment "allow_other_uses: true" at two locations below)
# pinButton: GPIO1 #TX # physical button to controll the roller blind (up/stop/down/stop/up.......) (hold for +5 seconds to enter setup mode/press once to start closing, press again at maximum-/bottom position, lastly press at minimum-/top position)
# pinReedSwitch: GPIO12 #D6 # Used for window open/closed, a reed(magnetic) sensor
# #pinXtra: # Might be used for something of your choice
# pinDIR: GPIO2 # DIRECTION > A4988
# pinSTP: GPIO0 # STEP > A4988
# pinSLP: GPIO4 # SLEEP & RESET > A4988
# pinDIRReversed: 'false' # Change to true if roller blind goes up instead of down and vice versa (reverse direction)
# pinLED: GPIO2 # Used for the Wemos on board LED to indicate when in "setup-mode"/LED on
## MQTT
## Uncomment below if you want to control it using MQTT and uncomment "api:"-section for HA ESPHome API above
#mqtt:
# broker: $mqtt_broker_ip
# discovery: True
# username:
# password:
# on_message:
# topic: $sub_hostname/ir/send
# then:
# - remote_transmitter.transmit_raw:
# carrier_frequency: 38kHz
# code: !lambda |-
# std::string txstr = x;
# std::vector<int> txv;
# char * token;
# char seps[] = ",";
# token = strtok (&txstr[0],seps);
# while (token != NULL)
# {
# txv.push_back( atoi(token) );
# token = strtok (NULL, seps);
# }
# return txv;
## Enable Home Assistant ESPHome API
## Comment out this section if you are not using HA ESPHome API and instead use MQTT or if you use them as standalone units controlled via the "action" button. (standalone means you comment out both MQTT and API)
api:
encryption:
key: !secret api_key
reboot_timeout: 120s
# No changes needed below this line ##################################################################################################
# No changes needed below this line ##################################################################################################
# No changes needed below this line ##################################################################################################
# No changes needed below this line ##################################################################################################
## Board model
esp8266:
board: d1_mini
restore_from_flash: true
## ESPHome
esphome:
name: '${sub_hostname}'
friendly_name: '${sub_hostname} (${sub_friendly_name})'
on_boot:
- priority: -200.0
then:
- text_sensor.template.publish:
id: current_status
state: 'Started'
- stepper.report_position: # Set stepper to global variable
id: ${mystepper}
position: !lambda return id(${mystepper}_global);
- stepper.set_target: # Set stepper to global variable
id: ${mystepper}
target: !lambda return id(${mystepper}_global);
- if: # If blind is Closed
condition:
- lambda: 'return id(${mystepper}_global) == 0;'
then: # Publish state etc.
- cover.template.publish:
id: blinded
state: CLOSED
- globals.set:
id: last_action
value: '2'
- text_sensor.template.publish:
id: current_status
state: 'Closed'
- if: # If blind is Open
condition:
- lambda: 'return id(${mystepper}_global) == id(endstop);'
then: # Publish state etc.
- cover.template.publish:
id: blinded
state: OPEN
current_operation: IDLE
- globals.set:
id: last_action
value: '0'
- text_sensor.template.publish:
id: current_status
state: 'Open'
- if: # If blind is Neither
condition:
- lambda: 'return (id(${mystepper}_global) != 0) && (id(${mystepper}_global) != id(endstop));'
then: # # Publish state etc.
- cover.template.publish:
id: blinded
position: !lambda 'return (float(float(id(${mystepper}).current_position) / float(id(endstop))));'
current_operation: IDLE
- globals.set:
id: last_action
value: '0'
- text_sensor.template.publish:
id: current_status
state: !lambda |-
int pos = round(float(float(id(${mystepper}).current_position) / float(id(endstop))) * 100);
return (
("Open: ") +
(pos ? String(pos) + "%" : "")
).c_str();
## WIFI
wifi:
power_save_mode: HIGH
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true
use_address: ${coverip}
manual_ip:
static_ip: ${coverip}
gateway: ${covergateway}
subnet: ${coversubnet}
## Enable fallback hotspot (captive portal) in case wifi connection fails...
ap:
ssid: '${sub_hostname} Hotspot'
password: !secret ap_fallback_wifi_password
## Webserver
web_server:
port: 80
## Enable logging
logger:
# level: VERBOSE
## Captive portal
captive_portal:
## OTA
ota:
platform: esphome
password: !secret ota_password
## Sync time with Home Assistant.
time:
- platform: homeassistant
id: homeassistant_time
## Send IR codes (IR-blaster)
#remote_transmitter:
# pin:
# number: $pinIRSend
# carrier_duty_percent: 50%
## Text sensors with general information.
text_sensor:
## Expose ESPHome version as sensor.
- platform: version
name: 'ESPHome Version'
## Expose WiFi information as sensors.
- platform: wifi_info
ip_address:
name: 'IP'
icon: 'mdi:ip-network-outline'
ssid:
name: 'SSID'
icon: 'mdi:access-point'
bssid:
name: 'BSSID'
icon: 'mdi:access-point'
mac_address:
name: 'MAC'
icon: 'mdi:expansion-card-variant'
- platform: template
name: 'Friendly Name'
icon: 'mdi:heart-outline'
lambda: |-
return {"${sub_friendly_name}"};
- platform: template
name: 'Last Action'
update_interval: never
id: current_status
icon: 'mdi:chart-box-outline'
- platform: template
name: 'Setup Position'
id: setup_position
icon: 'mdi:null'
- platform: template
name: 'Uptime HR'
id: uptime_human
icon: 'mdi:timer-outline'
- platform: template
name: 'Reversed Direction'
id: stepper_operation
icon: 'mdi:swap-vertical-circle-outline'
lambda: |-
return {"${pinDIRReversed}"};
## Buttons
button:
## Button to restart the device
- platform: restart
name: 'Restart'
icon: 'mdi:restart'
- platform: safe_mode
name: 'Restart (Safe Mode)'
icon: 'mdi:restart-alert'
- platform: template
name: 'Action Button' # Button to replicate the Physical Button once Settings Mode has been entered
icon: 'mdi:gesture-tap-button'
on_press:
- if: # If settings variable is on
condition:
- lambda: 'return id(settingmode) != 0;'
then: # Enter Setting Mode
- script.execute: setupbutton
## Sensors with general information.
sensor:
## Uptime sensor.
- platform: uptime
name: 'Uptime'
id: 'upptime'
icon: 'mdi:timer-outline'
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(upptime).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? String(days) + "d " : "") +
(hours ? String(hours) + "h " : "") +
(minutes ? String(minutes) + "m " : "") +
(String(seconds) + "s")
).c_str();
## WiFi Signal sensor.
- platform: wifi_signal
name: 'WiFi Signal'
update_interval: 120s
icon: 'mdi:wifi-strength-3'
## Binary sensors
binary_sensor:
# - platform: gpio
# pin:
# number: $pinPIR
# name: '${sub_hostname} motion'
# device_class: motion
- platform: gpio
pin:
number: ${pinButton} # Connect Button to your desired pin and GND
mode: INPUT_PULLUP
inverted: true # If using a touch sensor instead of a "physical" button set this to false, else set it to true
name: 'Action Button'
internal: true
on_click:
- min_length: 50ms
max_length: 500ms
then: # Short press to OPEN/CLOSE blinds and also for setting up
- if: # If settings variable is on
condition:
- lambda: 'return id(settingmode) != 0;'
then: # Enter Setting Mode
- script.execute: setupbutton
else:
- if: # If blind is stopped while opening #0=STOPPED WHILE OPENING
condition:
- lambda: 'return id(last_action) == 0;'
then:
- text_sensor.template.publish:
id: current_status
state: 'Closing...'
- globals.set:
id: last_action
value: '1'
- lambda: 'auto call = id(blinded).make_call().set_command_close(); call.perform();'
else:
- if: # If blind is moving down #1=MOVING DOWN
condition:
- lambda: 'return id(last_action) == 1;'
then:
- text_sensor.template.publish:
id: current_status
state: !lambda |-
int pos = round(float(float(id($mystepper).current_position) / float(id(endstop))) * 100);
return (
(pos ? String(pos) + "% open" : "") +
(" / Stopped while closing")
).c_str();
- globals.set:
id: last_action
value: '2'
- lambda: 'auto call = id(blinded).make_call().set_command_stop(); call.perform();'
else:
- if: # If blind is stopped while closing #2=STOPPED WHILE CLOSING
condition:
- lambda: 'return id(last_action) == 2;'
then:
- text_sensor.template.publish:
id: current_status
state: 'Opening...'
- globals.set:
id: last_action
value: '3'
- lambda: 'auto call = id(blinded).make_call().set_command_open(); call.perform();'
else:
- if: # If blind is moving up #3=MOVING UP
condition:
- lambda: 'return id(last_action) == 3;'
then:
- text_sensor.template.publish:
id: current_status
state: !lambda |-
int pos = round(float(float(id(${mystepper}).current_position) / float(id(endstop))) * 100);
return (
(pos ? String(pos) + "% open" : "") +
(" / Stopped while opening")
).c_str();
- globals.set:
id: last_action
value: '0'
- lambda: 'auto call = id(blinded).make_call().set_command_stop(); call.perform();'
- min_length: 4000ms
max_length: 10000ms
then: # Long press to Enter Setting Mode (4-10 Sec press)
- logger.log: 'Entered Settings Mode'
- switch.turn_on:
id: blue_led
- globals.set:
id: settingmode
value: '1'
- text_sensor.template.publish:
id: current_status
state: 'Setup activated, click to start'
- platform: gpio
pin:
number: $pinReedSwitch
mode: INPUT_PULLUP
name: 'Window'
filters:
- delayed_on: 1000ms
device_class: window
## Stepper
stepper:
- platform: a4988
id: $mystepper
dir_pin:
number: ${pinDIR}
#Legacy uncomment "allow_other_uses: true" if using old pcb
#allow_other_uses: true
inverted: ${pinDIRReversed}
step_pin:
number: ${pinSTP}
inverted: false
sleep_pin:
number: ${pinSLP}
inverted: false
max_speed: '${speed}' # Speed of the motor
acceleration: inf
deceleration: inf
## Globals
globals:
- id: ${mystepper}_global # Integer for storing the stepper position in case of reboot
type: int
restore_value: true
initial_value: '0'
- id: openclosed # Boolean to store OPEN/CLOSED state
type: bool
restore_value: true
initial_value: '0'
- id: endstop # Variable for storing ENDSTOP (how far to move stepper)
type: int
restore_value: true
initial_value: '1000'
- id: settingmode # Integer for Setup Mode
type: int
restore_value: no
initial_value: '0'
- id: feedback # Boolean for continuous feedback
type: bool
restore_value: no
initial_value: '1' # Default value for continuous feedback: Set to '1' and the cover reports back current position continuously / Set to '0' and the cover updates in the beginning and end of the requested operation
- id: last_action # Integer for last action
type: int
restore_value: no
# initial_value: '0'
## 0=STOPPED WHILE OPENING
## 1=CLOSING / MOVING DOWN
## 2=STOPPED WHILE CLOSING
## 3=OPENING / MOVING UP
number:
- platform: template
name: 'Speed'
id: rollerspeed
icon: 'mdi:speedometer'
max_value: '${maxspeed}'
min_value: '${minspeed}'
step: '${speedsteps}'
mode: slider
initial_value: '${speed}'
optimistic: true
on_value:
- stepper.set_speed:
id: '${mystepper}'
speed: !lambda "return x;"
- text_sensor.template.publish:
id: current_status
state: 'Set new steps/s for stepper motor'
## Switch
switch:
- platform: template
name: 'Activate Setup' # Switch to enter Setup Mode
id: setupswitch
icon: 'mdi:cog-outline'
lambda: |-
if (id(settingmode) != 0) {
return true;
} else {
return false;
}
turn_on_action:
then:
- logger.log: 'Entered Settings Mode'
- globals.set:
id: settingmode
value: '1'
- text_sensor.template.publish:
id: setup_position
state: 'S0'
- text_sensor.template.publish:
id: current_status
state: 'Setup has been activated, click [Action Button] to set and store the closed and open positions.'
- switch.turn_on:
id: blue_led
turn_off_action:
then:
- logger.log: 'Exiting Settings Mode'
- globals.set:
id: settingmode
value: '0'
- text_sensor.template.publish:
id: setup_position
state: ''
- text_sensor.template.publish:
id: current_status
state: 'Setup cancelled'
- switch.turn_off:
id: blue_led
- platform: template
name: 'Continuous Feedback' # Switch to activate continuous feedback
id: feedbackswitch
icon: 'mdi:sync'
lambda: |-
if (id(feedback) != 0) {
return true;
} else {
return false;
}
restore_mode: RESTORE_DEFAULT_ON
turn_on_action:
- logger.log: 'Activated Continuous Feedback'
- globals.set:
id: feedback
value: '1'
- text_sensor.template.publish:
id: current_status
state: 'Activated Continuous Feedback'
turn_off_action:
- logger.log: 'Disabled Continuous Feedback'
- globals.set:
id: feedback
value: '0'
- text_sensor.template.publish:
id: current_status
state: 'Disabled Continuous Feedback'
- platform: gpio
name: 'Blue LED'
internal: true
id: blue_led
icon: 'mdi:alarm-light'
pin:
number: ${pinLED}
#Legacy uncomment "allow_other_uses: true" if using old pcb
#allow_other_uses: true
mode: OUTPUT
inverted: true
restore_mode: ALWAYS_OFF
## Cover
cover:
- platform: template
name: 'Roller'
id: blinded
open_action:
then:
- logger.log: 'Opening'
- stepper.set_target: # Send stepper to endstop
id: ${mystepper}
target: !lambda return id(endstop);
- text_sensor.template.publish:
id: current_status
state: 'Opening'
- if: # If continuous feedback switch is on
condition:
- lambda: 'return id(feedback) != 0;'
then: # With continuous feedback
- while:
condition:
lambda: 'return id(${mystepper}).current_position != id(endstop);'
then:
- cover.template.publish:
id: blinded
position: !lambda 'return (float(float(id(${mystepper}).current_position) / float(id(endstop))));'
current_operation: OPENING
- delay: ${delaybetweenupdates}
else: # Without contiunous feedback
- cover.template.publish:
id: blinded
position: !lambda 'return (float(float(id(${mystepper}).current_position) / float(id(endstop))));'
current_operation: OPENING
- wait_until: # Wait until endstop reached
lambda: 'return (id(${mystepper}).current_position == id(endstop));'
- globals.set: # Set global to current position
id: ${mystepper}_global
value: !lambda return id($mystepper).current_position;
- globals.set: # Set toggle to OPEN (No need for 'optimistic mode')
id: openclosed
value: '1'
- cover.template.publish:
id: blinded
state: OPEN
current_operation: IDLE
- globals.set:
id: last_action
value: '0'
- text_sensor.template.publish:
id: current_status
state: 'Open'
close_action:
then:
- logger.log: 'Closing'
- stepper.set_target: # Send stepper to 0
id: ${mystepper}
target: '0'
- text_sensor.template.publish:
id: current_status
state: 'Closing'
- if: # If continuous feedback switch is on
condition:
- lambda: 'return id(feedback) != 0;'
then: # With continuous feedback
- while:
condition:
lambda: 'return id(${mystepper}).current_position != 0;'
then:
- cover.template.publish:
id: blinded
position: !lambda 'return (float(float(id(${mystepper}).current_position) / float(id(endstop))));'
current_operation: CLOSING
- delay: ${delaybetweenupdates}
else: # Without continuous feedback
- cover.template.publish:
id: blinded
position: !lambda 'return (float(float(id(${mystepper}).current_position) / float(id(endstop))));'
current_operation: CLOSING
- wait_until: # Wait until endstop reached
lambda: 'return id(${mystepper}).current_position == 0;'
- globals.set: # Set global to current position
id: ${mystepper}_global
value: !lambda return id($mystepper).current_position;
- globals.set: # Set toggle to CLOSED (No need for 'optimistic mode')
id: openclosed
value: '0'
- cover.template.publish:
id: blinded
state: CLOSED
current_operation: IDLE
- globals.set:
id: last_action
value: '2'
- text_sensor.template.publish:
id: current_status
state: 'Closed'
position_action:
then:
- stepper.set_target:
id: ${mystepper}
target: !lambda return int(id(endstop) * pos);
- text_sensor.template.publish:
id: current_status
state: !lambda |-
return (
(pos ? "Moving to set position: " + String(int(pos * 100)) + "%" : "")
).c_str();
- if: # If continuous feedback switch is on
condition:
- lambda: 'return id(feedback) != 0;'
then: # With continuous feedback
- while:
condition:
lambda: 'return id(${mystepper}).current_position != int(id(endstop) * pos);'
then:
- cover.template.publish:
id: blinded
position: !lambda 'return (float(float(id(${mystepper}).current_position) / float(id(endstop))));'
- delay: ${delaybetweenupdates}
else: # Without continuous feedback
- wait_until: # Wait until endstop reached
lambda: 'return id(${mystepper}).current_position == (int(id(endstop) * pos));'
- globals.set: # Set global to current position
id: ${mystepper}_global
value: !lambda return id(${mystepper}).current_position;
- cover.template.publish:
id: blinded
position: !lambda 'return (float(float(id(${mystepper}).current_position) / float(id(endstop))));'
current_operation: IDLE
- text_sensor.template.publish:
id: current_status
state: !lambda |-
return (
(pos ? "Reached set position: " + String(int(pos * 100)) + "%" : "")
).c_str();
stop_action:
then:
- stepper.set_target:
id: ${mystepper}
target: !lambda return id(${mystepper}).current_position;
- globals.set: # Set global to current position
id: ${mystepper}_global
value: !lambda return id(${mystepper}).current_position;
- cover.template.publish:
id: blinded
position: !lambda 'return (float(float(id(${mystepper}).current_position) / float(id(endstop))));'
current_operation: IDLE
- text_sensor.template.publish:
id: current_status
state: 'Stopped'
has_position: true
device_class: blind
## Scripts
script:
- id: setupbutton
then:
- if:
condition:
- lambda: 'return (id(settingmode) == 3);'
then:
- logger.log: 'Pressed Action Button: Mode 3'
- stepper.set_target: # Set Stepper position
id: ${mystepper}
target: !lambda return id(${mystepper}).current_position;
- globals.set: # Set Endstop Variable
id: endstop
value: !lambda return id(${mystepper}).current_position;
- globals.set: # Set Global stepper position
id: ${mystepper}_global
value: !lambda return id(${mystepper}).current_position;
- globals.set: # Reset Setting Mode
id: settingmode
value: '0'
- globals.set: # Set toggle to Open
id: openclosed
value: '1'
- cover.template.publish:
id: blinded
state: OPEN
current_operation: IDLE
- logger.log: 'Exiting Setting Mode'
- text_sensor.template.publish:
id: setup_position
state: 'S3'
- text_sensor.template.publish:
id: current_status
state: 'Setup complete, settings stored.'
- switch.turn_off:
id: blue_led
- if:
condition:
- lambda: 'return (id(settingmode) == 2);'
then:
- logger.log: 'Pressed Action Button: Mode 2'
- stepper.report_position: # Reset Stepper position to 0
id: ${mystepper}
position: '0'
- stepper.set_target: # Reset Stepper position to 0
id: ${mystepper}
target: '0'
- globals.set: # Move stepper to 0 (doesn't move it's already there!)
id: ${mystepper}_global
value: '0'
- stepper.set_target: # Reset Stepper position to 72000
id: ${mystepper}
target: '720000'
- globals.set: # Advance setup to next mode
id: settingmode
value: '3'
- text_sensor.template.publish:
id: setup_position
state: 'S2'
- text_sensor.template.publish:
id: current_status
state: 'Step 2: Click [Action Button] when the wanted open position has been reached.'
- if:
condition:
- lambda: 'return (id(settingmode) == 1);'
then:
- logger.log: 'Pressed Action Button: Mode 1'
- stepper.report_position: # Set Stepper position to 72000, makes it move to 0 (Closed)
id: ${mystepper}
position: '720000'
- globals.set: # Advance setup to next mode
id: settingmode
value: '2'
- text_sensor.template.publish:
id: setup_position
state: 'S1'
- text_sensor.template.publish:
id: current_status
state: 'Step 1: Click [Action Button] when the wanted closed position has been reached.'