-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathHA-RollerFT.yaml
More file actions
1322 lines (1264 loc) · 53.4 KB
/
HA-RollerFT.yaml
File metadata and controls
1322 lines (1264 loc) · 53.4 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
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# WIP with abilty to fine tune endstops after setup
#
# REALiAM: https://github.com/R34LiAM/HA-Roller
# With inspiration from RoadkillUK: https://github.com/RoadkillUK/Motor-on-a-Roller-Blind-for-ESPHOME
# Verified working on ESPHome Device Builder 2025.2.2 but will probably work fine on later revisions (or earlier)
# All that needs to be changed before compiling and flashing is in the 'substitutions:' section below.
# you may need to change the 'Board model' 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, you need to have the web server enabled.
# OR use a hardwired button to configure it [Action Button].
# I recommend wiring a button so the roller can be controlled and configured "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 web server GUI.
# Setup option 1 (Easiest)
#-----------------------------
# Add the yaml-code from this repo to your Home Assistant dashboard (HA_CARD.yaml).
# 1) Expand the 'Setup, Settings and Parameters' section in the card and clicking '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 [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 the 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
# Fixed all (hopefully) poorly named variables
# Added support for "tweaking" endposition after setup is completed
# Commented out web server to save on resources, did alot for stability
# 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:
subHostname: 'rullgardin00' # hostname/devicename/esphome sensors (keep lcase)
subFriendlyName: 'Friendly neighborhood roller shade' # More easily identify you roller
coverIP: '192.168.0.22' # Static IP
coverGateway: '192.168.0.1'
coverSubnet: '255.255.255.0'
speed: '700' # Default 700 | 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' # Default 50 | With what value should the step/s (speed) increase/decrease when configuring.
minSpeed: '100' # Default 100 | What value could be set as the minimum step/s (speed).
maxSpeed: '1000' # Default 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
#mqttBrokerIP: '192.168.0.23'
delayBetweenUpdates: 500 ms # Default 500 ms | Milliseconds between updates being pushed to Home Assistant ESPHome API
msToEnterSetup: 3000 ms # Default 3000 ms | Milliseconds action button has do be held before entering setup mode (default 3000ms / 3 Seconds).
myStepper: my_stepper # Default my_stepper | Name of the stepper motor (leave as is) everythings breaks if you change.
# Tweakvalues, always change the value by a factor of two (2, 4, 8, 16, 32 and so on. One full revolution is 2048 steps).
tweakMax: '2048' # Default 2048 | 2048 is one full revolution of the stepper. This is the maximum number of steps to increase/decrease endstop with.
tweakMin: '32' # Default 32 | 32 is 1/64 of a full revolution of the stepper. This is the minimum number of steps to increase/decrease endstop with.
tweakInterval: '32' # Default 32 | This is how big the jump is when increasing or decreasing the the value between "tweakMax" and "tweakMin".
tweakInitial: '512' # Default 512 | This is the initial value of the input slider, 512 is a quarter revolution.
## 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' # Default false | Change to true if roller blind goes up instead of down and vice versa (reverse direction) this can not be changed at runtime
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) this can not be changed at runtime
# pinLED: GPIO2 # Used for the Wemos on board LED to indicate when in "setup-mode"/LED on
## Substitutions ends here...
# Normally no changes below these lines are needed ##################################################################################################
# Normally no changes below these lines are needed ##################################################################################################
# Normally no changes below these lines are needed ##################################################################################################
# Normally no changes below these lines are needed ##################################################################################################
## MQTT
## Uncomment below if you want to control it using MQTT and uncomment "api:"-section for HA ESPHome API above
#mqtt:
# broker: $mqttBrokerIP
# discovery: True
# username:
# password:
# on_message:
# topic: $subHostname/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: 300s # Default 300s
## Board model
esp8266:
board: d1_mini
restore_from_flash: true # Default true
## ESPHome
esphome:
name: '${subHostname}'
friendly_name: '${subHostname} (${subFriendlyName})'
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: rollerblind
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: rollerblind
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: rollerblind
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: none
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true # Default 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: '${subHostname} Hotspot'
password: !secret ap_fallback_wifi_password
## Web server, takes alot of resources so uncomment only if needed
#web_server:
# port: 80
## Enable logging
logger:
# level: NONE
# level: ERROR
# level: VERBOSE
# baud_rate: 0
## 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 {"${subFriendlyName}"};
- 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: 'Tweak Buttons Visible'
id: tweak_buttons_visible
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}"};
- platform: template
name: 'Endstop position'
id: endstop_position
icon: 'mdi:vector-circle-variant'
lambda: |-
return {String(id(endstop)).c_str()};
## 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(settingsmode) != 0;'
then: # Enter Setting Mode
- script.execute: setupscript
- if: # If tweak variable is on
condition:
- lambda: 'return id(tweakmode) != 0;'
then: # Enter Tweak Mode
- script.execute: tweakscript
- platform: template
name: 'Tweak Up'
icon: 'mdi:arrow-up-bold-hexagon-outline'
on_press:
- if: # Check if Tweak Mode is Activated
condition:
- lambda: |-
if ( id(tweakmode) != 0 ) {
return true;
} else {
return false;
}
then:
# If Tweak Mode is Activated Check if at Top Position
- if: # Adjusting Top Position Up
condition:
- lambda: |-
if ( id(tweakmode) == 2 && id(${myStepper}).current_position == id(endstop) ) {
return true;
} else {
return false;
}
then:
- if:
condition:
- lambda: |-
if ( id(tweakmode) == 2 && id(${myStepper}).current_position == id(endstop) ) {
return true;
} else {
return false;
}
then:
- stepper.set_target: # Set Stepper position
id: ${myStepper}
target: !lambda 'return id(endstop) + id(tweakstepsvalue);'
- globals.set: # Set Global stepper position
id: ${myStepper}_global
value: !lambda 'return id(endstop) + id(tweakstepsvalue);'
- globals.set: # Set Endstop Variable
id: endstop
value: !lambda 'return id(endstop) + id(tweakstepsvalue);'
- text_sensor.template.publish:
id: current_status
state: 'Tweak: Top Position Adjusted Upwards'
# If Tweak Mode is Activated Check if at Bottom Position
- if: # Adjusting Bottom Position Up
condition:
- lambda: |-
if ( id(tweakmode) == 3 && id(${myStepper}).current_position == 0 ) {
return true;
} else {
return false;
}
then:
- if:
condition:
- lambda: 'return (id(endstop) > id(tweakstepsvalue));'
then:
- stepper.set_target: # Set Stepper position to negative tweakstepsvalue
id: ${myStepper}
target: !lambda 'return (id(tweakstepsvalue)*-1);'
- stepper.report_position: # Reset Stepper position to current position - tweakstepsvalue
id: ${myStepper}
position: !lambda |-
return id($myStepper).current_position - id(tweakstepsvalue);
- stepper.set_target: # Reset Stepper position target to 0
id: ${myStepper}
target: '0'
- globals.set: # Set Global stepper position to 0
id: ${myStepper}_global
value: !lambda 'return 0;'
- globals.set: # Set Endstop Variable endstop - tweakstepsvalue
id: endstop
value: !lambda 'return id(endstop) - id(tweakstepsvalue);'
- text_sensor.template.publish:
id: current_status
state: 'Tweak: Bottom Position Adjusted Upwards'
- if:
condition:
- lambda: 'return (id(endstop) <= 0);'
then:
- stepper.set_target: # Set Stepper position to negative tweakstepsvalue
id: ${myStepper}
target: !lambda 'return (id(endstop)*-1);'
- stepper.report_position: # Reset Stepper position to current position - tweakstepsvalue
id: ${myStepper}
position: !lambda |-
return 0;
- stepper.set_target: # Reset Stepper position target to 0
id: ${myStepper}
target: '0'
- globals.set: # Set Global stepper position to 0
id: ${myStepper}_global
value: !lambda 'return 0;'
- globals.set: # Set Endstop Variable endstop - tweakstepsvalue
id: endstop
value: !lambda 'return 0;'
- text_sensor.template.publish:
id: current_status
state: 'Tweak: Bottom Position Adjusted Upwards'
- text_sensor.template.publish:
id: endstop_position
state: !lambda |-
return String(id(endstop)).c_str();
- platform: template
name: 'Tweak Down'
icon: 'mdi:arrow-down-bold-hexagon-outline'
on_press:
- if: # Check if Tweak Mode is Activated
condition:
- lambda: |-
if ( id(tweakmode) != 0 ) {
return true;
} else {
return false;
}
then:
# If Tweak Mode is Activated Check if at Top Position
- if: # Adjusting Top Position Down
condition:
- lambda: |-
if ( id(tweakmode) == 2 ) {
return true;
} else {
return false;
}
then:
- if:
condition:
- lambda: 'return (id(endstop) - id(tweakstepsvalue) >= 0);'
then:
- stepper.set_target: # Set Stepper position
id: ${myStepper}
target: !lambda 'return id(endstop) - id(tweakstepsvalue);'
- globals.set: # Set Global stepper position
id: ${myStepper}_global
value: !lambda 'return id(endstop) - id(tweakstepsvalue);'
- globals.set: # Set Endstop Variable
id: endstop
value: !lambda 'return id(endstop) - id(tweakstepsvalue);'
- text_sensor.template.publish:
id: current_status
state: 'Tweak: Top Position Adjusted Downwards'
- text_sensor.template.publish:
id: endstop_position
state: !lambda 'return String(id(endstop)).c_str();'
else:
- stepper.set_target: # Set Stepper position
id: ${myStepper}
target: !lambda 'return 0;'
- globals.set: # Set Global stepper position
id: ${myStepper}_global
value: !lambda 'return 0;'
- globals.set: # Set Endstop Variable
id: endstop
value: !lambda 'return 0;'
- text_sensor.template.publish:
id: current_status
state: 'Tweak: Top Position cant go lower'
- text_sensor.template.publish:
id: endstop_position
state: !lambda 'return String(id(endstop)).c_str();'
# If Tweak Mode is Activated Check if at Bottom Position
- if: # Adjusting Bottom Position Down
condition:
- lambda: |-
if ( id(tweakmode) == 3 && id(${myStepper}).current_position == 0 ) {
return true;
} else {
return false;
}
then:
- stepper.set_target: # Set Stepper position
id: ${myStepper}
target: !lambda 'return id(tweakstepsvalue);'
- stepper.report_position: # Reset Stepper position to 0
id: ${myStepper}
position: !lambda |-
return id($myStepper).current_position + id(tweakstepsvalue);
- stepper.set_target: # Reset Stepper position to 0
id: ${myStepper}
target: '0'
- globals.set: # Set Global stepper position
id: ${myStepper}_global
value: !lambda 'return 0;'
- globals.set: # Set Endstop Variable
id: endstop
value: !lambda 'return id(endstop) + id(tweakstepsvalue);'
- text_sensor.template.publish:
id: current_status
state: 'Tweak: Bottom Position Adjusted Downwards'
- text_sensor.template.publish:
id: endstop_position
state: !lambda 'return String(id(endstop)).c_str();'
## 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: '${subHostname} motion'
# device_class: motion
- platform: gpio
pin:
number: ${pinButton} # Connect Button to your desired pin and GND
mode: INPUT_PULLUP
inverted: true # Default 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 # Default 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(settingsmode) != 0;'
then: # Enter Setting Mode
- script.execute: setupscript
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(rollerblind).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(rollerblind).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(rollerblind).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(rollerblind).make_call().set_command_stop(); call.perform();'
- min_length: '${msToEnterSetup}' # Time needed to hold [Action button] to activate setup mode
max_length: 10000ms # Default 10000ms
then: # Long press to Enter Setup Mode (4-10 Sec press)
- logger.log: 'Entered Settings Mode'
- switch.turn_on:
id: blue_led
- globals.set:
id: settingsmode
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: 250ms
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 # Default false
sleep_pin:
number: ${pinSLP}
inverted: false # Default 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 # Default true
initial_value: '0'
- id: openclosed # Boolean to store OPEN/CLOSED state
type: bool
restore_value: true # Default true
initial_value: '0'
- id: endstop # Variable for storing ENDSTOP (how far to move stepper)
type: int
restore_value: true # Default true
initial_value: '1024' # Initial endstop value, without configuration this should be half a revolution
- id: settingsmode # 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'
- id: tweakmode # Integer for Tweak Mode
type: int
restore_value: no
initial_value: '0'
- id: tweakstepsvalue # Variable for storing how many steps to adjust endstop with in Tweak Mode
type: int
restore_value: no
initial_value: '${tweakInitial}' # Number of Steps to add to "enstop"//subtract from "endstop" / 2048=One Revolution, 1024=Half a Revolution, 512=Quarter Revolution and so on...
## 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 # Default 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'
- platform: template
name: 'Tweak Step Amount'
id: tweaksteps
icon: 'mdi:counter'
max_value: '${tweakMax}' # 2048 steps is one full revolution of the stepper
min_value: '${tweakMin}'
step: '${tweakInterval}'
mode: slider
initial_value: '${tweakInitial}'
optimistic: true # Default true
on_value:
- globals.set:
id: tweakstepsvalue
value: !lambda "return x;"
## Switch
switch:
- platform: template
name: 'Activate Setup' # Switch to enter Setup Mode
id: setupswitch
icon: 'mdi:cog-outline'
lambda: |-
if (id(settingsmode) != 0) {
return true;
} else {
return false;
}
turn_on_action:
then:
- logger.log: 'Entered Settings Mode'
- globals.set:
id: settingsmode
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: 'Exited Settings Mode'
- globals.set:
id: settingsmode
value: '0'
- if: # if setup was started then canceled set everything to 0
condition:
- lambda: 'return ( id(setup_position).state == "S1" || id(setup_position).state == "S2" );'
then:
- stepper.report_position: # Set Stepper position to 0
id: ${myStepper}
position: '0'
- stepper.set_target: # Set Stepper target to 0
id: ${myStepper}
target: '0'
- globals.set: # Set global Endstop Variable to 0
id: endstop
value: '0'
- text_sensor.template.publish:
id: endstop_position
state: '0'
- text_sensor.template.publish:
id: setup_position
state: ''
# - lambda: 'auto call = id(rollerblind).make_call().set_command_stop(); call.perform();'
- text_sensor.template.publish:
id: current_status
state: 'Setup cancelled'
- switch.turn_off:
id: blue_led
- platform: template
name: 'Activate Tweak Mode' # Switch to enter Tweak Mode
id: tweakswitch
icon: 'mdi:tune-vertical-variant'
lambda: |-
if (id(tweakmode) != 0) {
return true;
} else {
return false;
}
turn_on_action:
then:
- logger.log: 'Entered Tweak Mode'
- text_sensor.template.publish:
id: setup_position
state: 'F1'
- text_sensor.template.publish:
id: tweak_buttons_visible
state: '0'
- globals.set:
id: tweakmode
value: '1'
- text_sensor.template.publish:
id: current_status
state: 'Tweak Mode has been activated, click [Action Button] to move to and then adjust the open postion.'
- switch.turn_on:
id: blue_led
turn_off_action:
then:
- logger.log: 'Exited Tweak Mode'
- text_sensor.template.publish:
id: setup_position
state: ''
- text_sensor.template.publish:
id: tweak_buttons_visible
state: '0'
- globals.set:
id: tweakmode
value: '0'
# - lambda: 'auto call = id(rollerblind).make_call().set_command_stop(); call.perform();'
- text_sensor.template.publish:
id: current_status
state: 'Tweak Mode 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 # Default 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 # Default true
restore_mode: ALWAYS_OFF
## Cover
cover:
- platform: template
name: 'Roller'