Repository navigation
Expand file tree
/
Copy pathropener-product.yaml
More file actions
841 lines (810 loc) · 39.3 KB
/
Copy pathropener-product.yaml
File metadata and controls
841 lines (810 loc) · 39.3 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
# =============================================================================
# Ropener — product layer (curtain opener)
# =============================================================================
# The Ropener-specific behaviour that sits ON TOP of the shared valar-core +
# scheduling packages. Each board wrapper (firmware/VAL3000, firmware/VAL3100)
# includes:
#
# packages:
# valar_core: { url: .../valar-motion, files: [common/valar-core.yaml], ... }
# scheduling: { url: .../valar-motion, files: [common/scheduling.yaml], ... }
# product: !include ../common/ropener-product.yaml
#
# This layer owns: the cover, sensorless homing, the two-button gesture UI, the
# gear/distance math, and the schedule_open/schedule_close scripts the shared
# scheduling mixin calls. It reuses core's driver (id: driver), tuning entities,
# diagnostics, and web UI groups, and renames a few core entities via !extend so
# field units keep their existing Home Assistant entity_ids.
# =============================================================================
# Mechanical + gesture constants (compile-time; a new flash to change).
substitutions:
gear_distance_cm: "3.7699" # MK7 drive gear: cm of rope per revolution
steps_per_revolution: "1600" # 200 full steps * 8 microsteps
hold_run_ms: "700" # press longer than this = hold-to-run
tap_window_ms: "400" # rapid-tap chaining window
combo_home_ms: "3000" # both buttons held this long = set home
home_speed: "3000" # homing runs at this fixed speed (above the
# ~2000 drivetrain resonance; gentle into the
# stop; ~14 s for a full 1 m travel)
home_timeout_s: "60" # homing auto-aborts after this if not stopped
# -- backstops an accidental press and a
# mis-tuned StallGuard that never fires
# Product boot steps. Core (priority 600) has already configured the TMC2209 and
# stepper; here we resync the derived step count and restore the saved position
# so the cover comes up accurate without a re-home. (scheduling re-applies
# tz/location at priority -100, after this.)
# The API's reboot_timeout defaults to 15 min: if no *API* client connects in
# that window the device reboots. It counts native-API clients only — a browser
# on the web UI is not one. The Ropener is sold as working without Home
# Assistant, so a customer driving it purely from the browser got a controller
# that rebooted every 15 minutes, stopping the curtain mid-travel if it happened
# to be moving. 0 = never reboot for lack of a client.
#
# Trade-off: this also removes the watchdog that recovers a wedged API
# connection. Acceptable here — the users it was rebooting are the ones not
# using the API at all — and safe_mode still covers boot loops.
api:
reboot_timeout: 0s
esphome:
on_boot:
- priority: 400.0
then:
- script.execute: recompute_distance
- script.execute: recompute_tcoolthrs
- stepper.report_position:
id: driver
position: !lambda "return id(global_current_position);"
- stepper.set_target:
id: driver
target: !lambda "return id(global_current_position);"
# --- Product state (tuning/direction globals come from core; sun globals from
# the scheduling mixin) -----------------------------------------------------
globals:
- { id: global_distance_cm, type: int, restore_value: yes, initial_value: '30' }
- { id: global_distance_steps, type: int, restore_value: no, initial_value: '12732' }
- { id: global_state, type: int, restore_value: no, initial_value: '0' }
- { id: global_current_position, type: int, restore_value: yes, initial_value: '0' }
# Physical-button gesture state (runtime only).
- { id: b1_down, type: bool, restore_value: no, initial_value: 'false' }
- { id: b2_down, type: bool, restore_value: no, initial_value: 'false' }
- { id: b1_hold_active, type: bool, restore_value: no, initial_value: 'false' }
- { id: b2_hold_active, type: bool, restore_value: no, initial_value: 'false' }
- { id: b1_consumed, type: bool, restore_value: no, initial_value: 'false' }
- { id: b2_consumed, type: bool, restore_value: no, initial_value: 'false' }
- { id: b1_tap_count, type: int, restore_value: no, initial_value: '0' }
- { id: b1_last_tap_ms, type: uint32_t, restore_value: no, initial_value: '0' }
# Button 2 gets its own tap counter too: with "Swap Buttons" ON, Button 2 is the
# close button, so it -- not Button 1 -- carries the 7-tap homing gesture. Only
# whichever button is currently the close button ever increments its counter.
- { id: b2_tap_count, type: int, restore_value: no, initial_value: '0' }
- { id: b2_last_tap_ms, type: uint32_t, restore_value: no, initial_value: '0' }
# Persisted button-swap state. Like global_stepper_direction, it is the single
# source of truth behind a stateless "Swap Buttons" select (see the select block).
- { id: global_btn_swap, type: bool, restore_value: yes, initial_value: 'false' }
# --- Stall handling (homing) ------------------------------------------------
# The Ropener homes sensorlessly: drive at the closed end until StallGuard fires,
# and treat THAT stall as position 0. Core's default on_stall zeroes the position
# unconditionally, which is wrong here — a stall mid-travel (curtain snags) would
# silently redefine that spot as home and corrupt the cover's position reference.
#
# `!extend` APPENDS to core's action list rather than replacing it, so extending
# alone would leave core's unconditional zeroing firing before ours. The two
# entries below are deliberate and order-dependent: the first deletes core's
# handler outright, the second installs the Ropener's conditional one. Verified
# against the resolved config — exactly one on_stall survives. Keep both.
stepper:
- id: !extend driver
on_stall: !remove
- id: !extend driver
# StallGuard is an OPT-IN advanced feature (sg_enabled, default OFF). When it
# is off, this handler no-ops even if the chip flags a stall, so the default
# product never reacts to StallGuard at all — homing is fully manual. `!extend`
# APPENDS, so the two entries above are order-dependent: !remove deletes core's
# unconditional zeroing, then this installs ours. Verified against the resolved
# config — exactly one on_stall survives.
on_stall:
- if:
condition:
lambda: 'return id(sg_enabled).state;'
then:
- stepper.stop: driver
- if:
condition:
lambda: 'return id(global_state) == 3;'
then:
# Genuine stall while homing = the end stop. Commit home.
- script.execute: home_finish
# Stall outside homing (snag, or hit the far end): stop and settle,
# but LEAVE position alone — this point is not home, and zeroing
# here is what corrupted v2.7.0.
else:
- globals.set: { id: global_state, value: "0" }
- cover.template.publish: { id: ropener_cover, current_operation: IDLE }
- logger.log: "Stall detected outside homing — motor stopped, position unchanged"
script:
# Derive TCOOLTHRS from the configured Speed.
#
# StallGuard only reports while TSTEP <= TCOOLTHRS, and TSTEP is inversely
# proportional to velocity. Measured on VAL3000 hardware (microsteps=8),
# within 1% from Speed 3000 to 9000 under real curtain load:
#
# TSTEP ~= 374000 / Speed
#
# So the shipped default of TCOOLTHRS=100 arms only above Speed ~3740. Below
# that, StallGuard is switched off entirely -- no error, no log line, nothing
# in the UI, and homing simply never completes. That is a setting a customer
# can reach just by dragging the Speed slider down for a quieter curtain.
#
# 2x cruise TSTEP arms from half of cruise speed upward at any Speed, which
# keeps the deliberate low-velocity cutoff (SG_RESULT is unreliable when slow,
# which is what TCOOLTHRS is for) while guaranteeing it actually engages.
- id: recompute_tcoolthrs
then:
- lambda: |-
uint32_t sp = id(global_speed) > 0 ? (uint32_t) id(global_speed) : 1;
uint32_t v = 748000UL / sp;
if (v > 1048575) v = 1048575; // TCOOLTHRS is a 20-bit register
id(global_tcoolthrs) = (int) v;
id(driver)->write_register(TCOOLTHRS, v);
# Recompute the derived step cache from the persisted centimeters (one place).
- id: recompute_distance
then:
- globals.set:
id: global_distance_steps
value: !lambda "return (float(id(global_distance_cm)) / ${gear_distance_cm}) * ${steps_per_revolution};"
# --- Homing (manual by default; StallGuard only assists when sg_enabled) -----
# Drive toward the closed end at a fixed gentle speed. It ends one of three
# ways: the user presses Start-Stop again (home_finish), the timeout fires
# (home_abort), or -- only if sg_enabled -- StallGuard trips (home_finish).
#
# Drives RELATIVE (current - 100000) and does NOT zero at start, so an aborted
# home leaves the position honest instead of committing a false zero. Home is
# committed to 0 only by a deliberate finish.
- id: home_start
then:
- globals.set: { id: global_state, value: "3" }
- cover.template.publish: { id: ropener_cover, current_operation: CLOSING }
- stepper.set_speed:
id: driver
speed: ${home_speed}
- stepper.set_target:
id: driver
target: !lambda "return id(driver)->current_position - 100000;"
- script.execute: home_timeout
- logger.log: "Homing started — press Start-Stop again at the closed end to set home"
# Reached the real closed end: commit position 0 as home, restore run speed.
- id: home_finish
then:
- script.stop: home_timeout
- stepper.stop: driver
- stepper.report_position: { id: driver, position: 0 }
- stepper.set_target: { id: driver, target: 0 }
- stepper.set_speed: { id: driver, speed: !lambda "return id(global_speed);" }
- globals.set: { id: global_state, value: "0" }
- globals.set: { id: global_current_position, value: "0" }
- cover.template.publish: { id: ropener_cover, current_operation: IDLE }
- logger.log: "Home set to 0"
# Timeout (or any abort): stop, restore run speed, and DO NOT set home. The
# position is left exactly where it is -- committing a home on an accidental or
# timed-out press is what corrupts the reference and inverts open/close.
- id: home_abort
then:
- stepper.stop: driver
- stepper.set_target:
id: driver
target: !lambda "return id(driver)->current_position;"
- stepper.set_speed: { id: driver, speed: !lambda "return id(global_speed);" }
- globals.set: { id: global_state, value: "0" }
- cover.template.publish: { id: ropener_cover, current_operation: IDLE }
- logger.log: "Homing timed out — aborted, home NOT set (position unchanged)"
# Unconditional backstop: if still homing after home_timeout_s, abort. Covers an
# accidental Start-Stop press AND a mis-tuned StallGuard that never trips.
- id: home_timeout
mode: restart
then:
- delay: ${home_timeout_s}s
- if:
condition: { lambda: 'return id(global_state) == 3;' }
then:
- script.execute: home_abort
# Declare current position as home (0) — the two-button "set home here" combo.
- id: set_home_zero
then:
- script.stop: home_timeout
- stepper.stop: driver
- stepper.report_position: { id: driver, position: 0 }
- stepper.set_target: { id: driver, target: 0 }
- stepper.set_speed: { id: driver, speed: !lambda "return id(global_speed);" }
- globals.set: { id: global_state, value: "0" }
- globals.set: { id: global_current_position, value: "0" }
- cover.template.publish: { id: ropener_cover, current_operation: IDLE }
- logger.log: "Home position set to 0"
# Hold-to-run engage (armed on press, fired after hold_run_ms).
# Hold-to-run for each button. The MOTION depends on the button's current role
# (set by the "Swap Buttons" select): the close button drives close, the open
# button drives open. Button 1 is the close button when swap is OFF; Button 2 is
# the close button when swap is ON.
- id: b1_hold_check
mode: restart
then:
- delay: ${hold_run_ms}ms
- if:
condition:
lambda: 'return id(b1_down) && !id(b2_down) && id(global_state) == 0 && id(b1_tap_count) < 7;'
then:
- globals.set: { id: b1_hold_active, value: "true" }
- globals.set: { id: b1_consumed, value: "true" }
- if:
condition: { lambda: 'return !id(global_btn_swap);' }
then:
- cover.close: ropener_cover
- logger.log: "Button 1 held: closing while held"
else:
- cover.open: ropener_cover
- logger.log: "Button 1 held: opening while held"
- id: b2_hold_check
mode: restart
then:
- delay: ${hold_run_ms}ms
- if:
condition:
lambda: 'return id(b2_down) && !id(b1_down) && id(global_state) == 0 && id(b2_tap_count) < 7;'
then:
- globals.set: { id: b2_hold_active, value: "true" }
- globals.set: { id: b2_consumed, value: "true" }
- if:
condition: { lambda: 'return id(global_btn_swap);' }
then:
- cover.close: ropener_cover
- logger.log: "Button 2 held: closing while held"
else:
- cover.open: ropener_cover
- logger.log: "Button 2 held: opening while held"
# Deferred single-tap CLOSE, one per button. Only the current close button ever
# schedules its commit (the open button opens immediately on release); the delay
# lets a 7-tap homing burst chain without the first tap committing a close.
- id: b1_tap_commit
mode: restart
then:
- delay: ${tap_window_ms}ms
- if:
condition:
lambda: 'return id(global_state) == 0 && id(b1_tap_count) < 7;'
then:
- cover.close: ropener_cover
- logger.log: "Button 1 tap: closing"
- globals.set: { id: b1_tap_count, value: "0" }
- id: b2_tap_commit
mode: restart
then:
- delay: ${tap_window_ms}ms
- if:
condition:
lambda: 'return id(global_state) == 0 && id(b2_tap_count) < 7;'
then:
- cover.close: ropener_cover
- logger.log: "Button 2 tap: closing"
- globals.set: { id: b2_tap_count, value: "0" }
# Two-button "set home" combo.
- id: combo_home
mode: restart
then:
- delay: ${combo_home_ms}ms
- if:
condition:
lambda: 'return id(b1_down) && id(b2_down);'
then:
- script.execute: set_home_zero
- globals.set: { id: b1_consumed, value: "true" }
- globals.set: { id: b2_consumed, value: "true" }
- globals.set: { id: b1_tap_count, value: "0" }
- logger.log: "Both buttons held: home position set"
# ---- Scheduling contract (called by common/scheduling.yaml) ----------------
# scheduling decides WHEN; these decide HOW. Guard against interrupting homing.
- id: schedule_open
then:
- if:
condition:
lambda: 'return id(global_state) != 3;'
then:
- cover.open: ropener_cover
- id: schedule_close
then:
- if:
condition:
lambda: 'return id(global_state) != 3;'
then:
- cover.close: ropener_cover
# --- Attach Ropener button behaviour onto core's bare buttons (btn1/btn2/btn3)
binary_sensor:
- id: !extend btn1
on_press:
- globals.set: { id: b1_down, value: "true" }
- if:
condition: { lambda: 'return id(global_state) == 3;' }
then:
- script.stop: b1_hold_check
- script.stop: b1_tap_commit
- script.execute: set_home_zero
- globals.set: { id: b1_consumed, value: "true" }
- globals.set: { id: b1_tap_count, value: "0" }
- logger.log: "Homing cancelled (Button 1)"
else:
- if:
condition: { lambda: 'return id(global_state) == 1 || id(global_state) == 2;' }
then:
- script.stop: b1_hold_check
- script.stop: b1_tap_commit
- cover.stop: ropener_cover
- globals.set: { id: b1_consumed, value: "true" }
- globals.set: { id: b1_tap_count, value: "0" }
else:
- if:
condition: { lambda: 'return id(b2_down);' }
then:
- script.stop: b1_hold_check
- script.stop: b2_hold_check
- script.stop: b1_tap_commit
- script.stop: b2_tap_commit
- cover.stop: ropener_cover
- globals.set: { id: b1_hold_active, value: "false" }
- globals.set: { id: b2_hold_active, value: "false" }
- globals.set: { id: b1_consumed, value: "true" }
- globals.set: { id: b2_consumed, value: "true" }
- script.execute: combo_home
else:
# Idle, single button. Behaviour depends on Button 1's role.
- if:
condition: { lambda: 'return !id(global_btn_swap);' }
then:
# CLOSE button: count taps (7 -> homing), defer the close.
- script.stop: b1_tap_commit
- lambda: |-
uint32_t now = millis();
if (now - id(b1_last_tap_ms) > ${tap_window_ms}) id(b1_tap_count) = 0;
id(b1_tap_count) += 1;
id(b1_last_tap_ms) = now;
- globals.set: { id: b1_consumed, value: "false" }
- if:
condition: { lambda: 'return id(b1_tap_count) >= 7;' }
then:
- script.stop: b1_hold_check
- globals.set: { id: b1_tap_count, value: "0" }
- globals.set: { id: b1_consumed, value: "true" }
- script.execute: home_start
- logger.log: "Button 1 x7: starting homing"
else:
- script.execute: b1_hold_check
else:
# OPEN button: no homing gesture; open immediately on release.
- globals.set: { id: b1_tap_count, value: "0" }
- globals.set: { id: b1_consumed, value: "false" }
- script.execute: b1_hold_check
on_release:
- globals.set: { id: b1_down, value: "false" }
- script.stop: b1_hold_check
- script.stop: combo_home
- if:
condition: { lambda: 'return id(b1_hold_active);' }
then:
- cover.stop: ropener_cover
- globals.set: { id: b1_hold_active, value: "false" }
- globals.set: { id: b1_consumed, value: "false" }
- logger.log: "Button 1 released: stopped"
else:
- if:
condition: { lambda: 'return id(b1_consumed);' }
then:
- globals.set: { id: b1_consumed, value: "false" }
else:
# Tap: the close button defers (allows 7-tap chaining); the open
# button opens immediately.
- if:
condition: { lambda: 'return !id(global_btn_swap);' }
then:
- script.execute: b1_tap_commit
else:
- cover.open: ropener_cover
- logger.log: "Button 1 tap: opening"
- id: !extend btn2
on_press:
- globals.set: { id: b2_down, value: "true" }
- if:
condition: { lambda: 'return id(global_state) == 3;' }
then:
- script.stop: b2_hold_check
- script.stop: b2_tap_commit
- script.execute: set_home_zero
- globals.set: { id: b2_consumed, value: "true" }
- globals.set: { id: b2_tap_count, value: "0" }
- logger.log: "Homing cancelled (Button 2)"
else:
- if:
condition: { lambda: 'return id(global_state) == 1 || id(global_state) == 2;' }
then:
- script.stop: b2_hold_check
- script.stop: b2_tap_commit
- cover.stop: ropener_cover
- globals.set: { id: b2_consumed, value: "true" }
- globals.set: { id: b2_tap_count, value: "0" }
else:
- if:
condition: { lambda: 'return id(b1_down);' }
then:
- script.stop: b1_hold_check
- script.stop: b2_hold_check
- script.stop: b1_tap_commit
- script.stop: b2_tap_commit
- cover.stop: ropener_cover
- globals.set: { id: b1_hold_active, value: "false" }
- globals.set: { id: b2_hold_active, value: "false" }
- globals.set: { id: b1_consumed, value: "true" }
- globals.set: { id: b2_consumed, value: "true" }
- globals.set: { id: b1_tap_count, value: "0" }
- globals.set: { id: b2_tap_count, value: "0" }
- script.execute: combo_home
else:
# Idle, single button. Behaviour depends on Button 2's role.
- if:
condition: { lambda: 'return id(global_btn_swap);' }
then:
# CLOSE button (swap ON): count taps (7 -> homing), defer close.
- script.stop: b2_tap_commit
- lambda: |-
uint32_t now = millis();
if (now - id(b2_last_tap_ms) > ${tap_window_ms}) id(b2_tap_count) = 0;
id(b2_tap_count) += 1;
id(b2_last_tap_ms) = now;
- globals.set: { id: b2_consumed, value: "false" }
- if:
condition: { lambda: 'return id(b2_tap_count) >= 7;' }
then:
- script.stop: b2_hold_check
- globals.set: { id: b2_tap_count, value: "0" }
- globals.set: { id: b2_consumed, value: "true" }
- script.execute: home_start
- logger.log: "Button 2 x7: starting homing"
else:
- script.execute: b2_hold_check
else:
# OPEN button: no homing gesture; open immediately on release.
- globals.set: { id: b2_tap_count, value: "0" }
- globals.set: { id: b2_consumed, value: "false" }
- script.execute: b2_hold_check
on_release:
- globals.set: { id: b2_down, value: "false" }
- script.stop: b2_hold_check
- script.stop: combo_home
- if:
condition: { lambda: 'return id(b2_hold_active);' }
then:
- cover.stop: ropener_cover
- globals.set: { id: b2_hold_active, value: "false" }
- globals.set: { id: b2_consumed, value: "false" }
- logger.log: "Button 2 released: stopped"
else:
- if:
condition: { lambda: 'return id(b2_consumed);' }
then:
- globals.set: { id: b2_consumed, value: "false" }
else:
# Tap: the close button defers (allows 7-tap chaining); the open
# button opens immediately.
- if:
condition: { lambda: 'return id(global_btn_swap);' }
then:
- script.execute: b2_tap_commit
else:
- cover.open: ropener_cover
- logger.log: "Button 2 tap: opening"
# Rename core's "Button 3 (Wi-Fi reset)" to Ropener's "WiFi Reset" and attach
# the hold-to-erase-credentials action.
- id: !extend btn3
name: "WiFi Reset"
on_click:
- min_length: 3000ms
max_length: 10000ms
then:
- logger.log: "Clearing saved Wi-Fi credentials and rebooting into setup"
- lambda: |-
esphome::wifi::global_wifi_component->save_wifi_sta("", "");
esphome::wifi::global_wifi_component->clear_sta();
- delay: 1s
- lambda: "App.safe_reboot();"
# --- Preserve the shipped "Motor Direction" option strings --------------------
# Field units (and any Home Assistant automation that selects a direction) know
# this option as "Reversed ↺" — the glyph is part of the string, not decoration.
# valar-core dropped it to a plain "Reversed", which would silently break those
# automations and leave existing units holding an option that no longer exists.
# `options` is a list, so !extend would APPEND and yield three choices; remove
# then re-add instead. `lambda` is a scalar, so extending overwrites it cleanly.
# Core's set_action matches on `x.find("Reversed")`, which still hits — no
# override needed there.
select:
- id: !extend sel_direction
options: !remove
- id: !extend sel_direction
options:
- "Normal"
- "Reversed ↺"
lambda: |-
if (id(global_stepper_direction) == esphome::tmc2209::ShaftDirection::COUNTERCLOCKWISE)
return std::string("Reversed ↺");
return std::string("Normal");
# Friendly Slow / Medium / Fast speed, chosen to straddle the ~2000 drivetrain
# resonance (measured): Slow 1500 sits below it, Medium 5000 and Fast 9000 above.
# Like Motor Direction, this holds NO state of its own -- it reads and writes
# global_speed (the single source of truth, restored on boot) so it never fights
# the restored value. The raw Speed slider lives in the advanced group.
- platform: template
name: "Speed"
id: sel_speed
icon: "mdi:speedometer"
entity_category: CONFIG
web_server: { sorting_weight: 1, sorting_group_id: group_tuning }
update_interval: 1s
options: ["Slow", "Medium", "Fast"]
lambda: |-
const int sp = id(global_speed);
if (sp <= 2000) return std::string("Slow"); // <= resonance edge
if (sp <= 6500) return std::string("Medium");
return std::string("Fast");
set_action:
- lambda: |-
int s = 9000; // Fast
if (x.find("Slow") != std::string::npos) s = 1500;
else if (x.find("Medium") != std::string::npos) s = 5000;
id(global_speed) = s;
- stepper.set_speed: { id: driver, speed: !lambda "return id(global_speed);" }
- script.execute: recompute_tcoolthrs
- lambda: |-
// Persist immediately, like Motor Direction, so the choice survives an
// unplug seconds later.
global_speed->update();
global_preferences->sync();
# Swap the two physical buttons' open/close roles -- same select UI as Motor
# Direction, and its sibling install-orientation setting (sits right under it in
# Setup). "Normal" = Button 1 closes, Button 2 opens (the shipped layout).
# "Swapped" = Button 1 opens, Button 2 closes -- for a mirror-image install (e.g.
# pull-rope on the left) where the flipped unit makes the buttons feel reversed.
# The 7-tap homing gesture and the deferred single-tap always follow the CLOSE
# button. Like Motor Direction it holds NO state of its own: it reads and writes
# the persisted global_btn_swap, so it never fights the restored value. Only
# remaps the on-device buttons; the web UI, Home Assistant, and the schedule
# open/close are unaffected. (A left-side install usually wants Motor Direction =
# Reversed too.)
- platform: template
name: "Swap Buttons"
id: sel_btn_swap
icon: "mdi:swap-horizontal"
entity_category: CONFIG
web_server: { sorting_weight: 2, sorting_group_id: group_setup }
update_interval: 1s
options:
- "Normal"
- "Swapped ↔"
lambda: |-
if (id(global_btn_swap)) return std::string("Swapped ↔");
return std::string("Normal");
set_action:
- lambda: |-
id(global_btn_swap) = (x.find("Swap") != std::string::npos);
global_btn_swap->update();
global_preferences->sync();
# --- Rename core tuning entities to Ropener's existing entity_ids -------------
number:
# Raw IRUN (register 1-31) is meaningless to users -- the friendly "Motor
# Current" number below drives it in milliamps instead. Keep the raw register
# in the advanced group for power users.
- id: !extend num_irun
name: "IRUN value"
web_server: { sorting_weight: 7, sorting_group_id: group_sg }
# Friendly motor current in mA. The driver knows Rsense (100 mOhm) and Vsense,
# so write_run_current_mA / read_run_current_mA do the register conversion --
# no formula here. Max is the register ceiling (~1915 mA at these settings);
# the motor is rated 2 A continuous, so nothing the driver can produce is
# thermally unsafe. Values snap to the nearest of 32 register steps (~60 mA).
- platform: template
name: "Motor Current"
id: num_motor_current
unit_of_measurement: "mA"
icon: "mdi:current-dc"
web_server: { sorting_weight: 3, sorting_group_id: group_tuning }
min_value: 100
max_value: 1900
step: 10
mode: BOX
entity_category: CONFIG
lambda: "return id(driver)->read_run_current_mA();"
update_interval: 5s
set_action:
- lambda: "id(driver)->write_run_current_mA((uint16_t) x);"
# Keep global_irun (persisted, reapplied in on_boot) in sync with the
# register field the driver just derived.
- globals.set:
id: global_irun
value: !lambda "return id(driver)->read_field(IRUN_FIELD);"
# TCOOLTHRS and SGTHRS are StallGuard tuning -> move them to the bottom group_sg
# (core puts them in group_stallguard, which we're retiring in favour of group_sg).
- id: !extend num_tcoolthrs
name: "TCOOLTHRS value"
web_server: { sorting_weight: 4, sorting_group_id: group_sg }
- id: !extend num_sgthrs
name: "SGTHRS value"
web_server: { sorting_weight: 3, sorting_group_id: group_sg }
# Raw Speed (steps/s) is now driven by the friendly Slow/Medium/Fast preset
# select below; keep the exact slider in the advanced group. !extend APPENDS to
# core's set_action, so core still stores global_speed and pushes it to the
# driver, then recompute_tcoolthrs runs.
- id: !extend num_speed
web_server: { sorting_weight: 8, sorting_group_id: group_sg }
set_action:
- script.execute: recompute_tcoolthrs
# Acceleration is core's last remaining member of group_motion (Speed moved to the
# advanced group above). Move it to group_tuning too so core's group_motion is fully
# empty and does not render a duplicate "Motion Tuning" header.
- id: !extend num_accel
web_server: { sorting_weight: 2, sorting_group_id: group_tuning }
# Product-only: travel distance in centimeters (drives the cover's 0..1 range).
- platform: template
name: "Centimeters"
web_server: { sorting_weight: 1, sorting_group_id: group_setup }
step: 1
min_value: 1
max_value: 9000
mode: BOX
entity_category: CONFIG
lambda: return id(global_distance_cm);
update_interval: 1s
set_action:
then:
- globals.set: { id: global_distance_cm, value: !lambda "return x;" }
- script.execute: recompute_distance
sensor:
# SG_RESULT and TSTEP are raw StallGuard tuning data -- meaningless with
# StallGuard off -- so move them out of Diagnostics into the StallGuard group,
# alongside SGTHRS/TCOOLTHRS and the enable switch.
- id: !extend sen_sgresult
name: "SG_RESULT Sensor"
web_server: { sorting_weight: 5, sorting_group_id: group_sg }
- id: !extend sen_tstep
name: "TSTEP Sensor"
web_server: { sorting_weight: 6, sorting_group_id: group_sg }
# --- The curtain cover --------------------------------------------------------
cover:
- platform: template
id: ropener_cover
name: Ropener
# A curtain draws sideways, not up and down. With no device_class the UI
# falls back to generic up/down arrows; "curtain" gets the horizontal
# open/close controls (and the right icon in Home Assistant).
device_class: curtain
web_server: { sorting_weight: 1, sorting_group_id: group_control }
has_position: true
assumed_state: false
lambda: "return float(id(driver)->current_position) / float(id(global_distance_steps));"
stop_action:
- stepper.stop: driver
- globals.set: { id: global_state, value: "0" }
- cover.template.publish: { id: ropener_cover, current_operation: IDLE }
open_action:
- globals.set: { id: global_state, value: "1" }
- cover.template.publish: { id: ropener_cover, current_operation: OPENING }
- stepper.set_target: { id: driver, target: !lambda return id(global_distance_steps); }
close_action:
- globals.set: { id: global_state, value: "2" }
- cover.template.publish: { id: ropener_cover, current_operation: CLOSING }
- stepper.set_target: { id: driver, target: 0 }
position_action:
- if:
condition:
lambda: 'return (pos * id(global_distance_steps)) >= id(driver)->current_position;'
then:
- globals.set: { id: global_state, value: "1" }
- cover.template.publish: { id: ropener_cover, current_operation: OPENING }
else:
- globals.set: { id: global_state, value: "2" }
- cover.template.publish: { id: ropener_cover, current_operation: CLOSING }
- stepper.set_target: { id: driver, target: !lambda return pos * id(global_distance_steps); }
button:
- platform: template
name: "Start-Stop Homing"
web_server: { sorting_weight: 3, sorting_group_id: group_control }
entity_category: DIAGNOSTIC
on_press:
- if:
condition: { lambda: 'return id(global_state) == 3;' }
then:
# Second press at the closed end: commit home.
- script.execute: home_finish
else:
# First press: start homing (drives closed at ${home_speed}).
- script.execute: home_start
# StallGuard is now advanced/experimental, so its controls sit at the very bottom.
# Core's group_sg (weight 40) can't be re-weighted from here -- package
# merge duplicates the id rather than overriding it -- so instead we define a NEW
# group below Diagnostics (60) and reassign every StallGuard entity to it. Core's
# original group is left with no members and does not render.
web_server:
sorting_groups:
# Core puts Motion Tuning at weight 30 (below Schedule at 25). We can't re-weight
# a core group from the product layer (the id would be redefined), so define a NEW
# group at weight 22 -- directly under Setup (20), above Schedule (25) -- and move
# every motion entity to it. Core's group_motion is left empty and does not render.
- { id: group_tuning, name: "Motion Tuning", sorting_weight: 22 }
- { id: group_sg, name: "StallGuard (experimental)", sorting_weight: 70 }
switch:
# Master opt-in for StallGuard. Default OFF: the shipped product homes manually
# (Start-Stop button) and never reacts to a chip stall. Turn this on only to
# use sensorless auto-homing / obstruction detection, which needs SGTHRS tuned
# to the installed load (see the StallGuard group). Mirrors Glasscalibur's
# stallguard_enabled. on_stall no-ops while this is off.
- platform: template
name: "StallGuard Enabled"
id: sg_enabled
icon: "mdi:shield-search"
entity_category: CONFIG
web_server: { sorting_weight: 1, sorting_group_id: group_sg }
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
text_sensor:
# Surfaces StallGuard's arming state, which is otherwise invisible. The
# failure it exists to catch: if TCOOLTHRS is below the cruise TSTEP for the
# configured Speed, StallGuard NEVER reports, homing never completes, and
# nothing anywhere says so. Diagnosed here from the configured Speed, so a
# misconfiguration is visible while the curtain is standing still rather than
# only discovered when homing silently fails.
#
# "Below threshold" during acceleration is normal and expected -- StallGuard
# is deliberately disarmed at low velocity, which is what TCOOLTHRS is for.
# A reading that never leaves it once at speed is the real fault.
- platform: template
name: "StallGuard"
id: sg_status
icon: "mdi:shield-search"
entity_category: DIAGNOSTIC
web_server: { sorting_weight: 2, sorting_group_id: group_sg }
update_interval: 1s
lambda: |-
if (!id(sg_enabled).state) return {"Disabled"};
const uint32_t tc = id(driver)->read_register(TCOOLTHRS);
// Predicted cruise TSTEP for the configured Speed (measured constant).
const uint32_t sp = id(global_speed) > 0 ? (uint32_t) id(global_speed) : 1;
const uint32_t cruise = 374000UL / sp;
if (cruise > tc)
return {"Never arms at this Speed"};
const uint32_t ts = id(driver)->read_register(TSTEP);
if (ts >= 0xFFFFF) return {"Ready (stopped)"};
if (ts <= tc) return {"Armed"};
return {"Below threshold"};
- platform: template
name: "State"
id: cover_state
web_server: { sorting_weight: 2, sorting_group_id: group_control }
update_interval: 500ms
lambda: |-
switch (id(global_state)) {
case 1: return {"OPENING"};
case 2: return {"CLOSING"};
case 3: return {"HOMING"};
default: return {"IDLE"};
}
# Motion-completion poll: persist position; flip OPENING/CLOSING back to IDLE
# when the stepper reaches target. (The sun-schedule poll lives in scheduling.)
interval:
- interval: 200ms
then:
- globals.set:
id: global_current_position
value: !lambda "return id(driver)->current_position;"
- if:
condition:
lambda: |-
int s = id(global_state);
return (s == 1 || s == 2) &&
id(driver)->current_position == id(driver)->target_position;
then:
- globals.set: { id: global_state, value: "0" }
- cover.template.publish: { id: ropener_cover, current_operation: IDLE }
- globals.set: { id: b1_hold_active, value: "false" }
- globals.set: { id: b2_hold_active, value: "false" }