I got 2 template covers that share 4 common relais (Power, direction and cover selection for positive and negative) - and no: unfortunately I can not control each one separately…
So I was looking for a means for some sort of mutex/lock in esphome that would delay/block the activity until the other step is finished.
The only thing that I found was that scripts allow for queuing - so they do not run in parallel…
So I have implemented it like this:
globals:
- id: klappe_oben_state
type: int
restore_value: no
initial_value: COVER_CLOSED
- id: klappe_unten_state
type: int
restore_value: no
initial_value: COVER_CLOSED
cover:
- platform: template
name: Klappe oben
id: klappe_oben
has_position: False
lambda: return id(klappe_oben_state);
open_action:
then:
- script.execute:
id: klappen_control
klappe: 0
open: true
- script.wait:
id: klappen_control
- globals.set:
id: klappe_oben_state
value: COVER_OPEN
close_action:
then:
- script.execute:
id: klappen_control
klappe: 0
open: false
- script.wait:
id: klappen_control
- globals.set:
id: klappe_oben_state
value: COVER_CLOSED
- platform: template
name: Klappe unten
id: klappe_unten
has_position: False
lambda: return id(klappe_unten_state);
open_action:
then:
- script.execute:
id: klappen_control
klappe: 1
open: true
- globals.set:
id: klappe_unten_state
value: COVER_OPEN
close_action:
then:
- script.execute:
id: klappen_control
klappe: 1
open: false
- globals.set:
id: klappe_unten_state
value: COVER_CLOSED
script:
- id: klappen_control
parameters:
klappe: int
open: bool
mode: queued
then:
- switch.turn_off: klappen_power
- if:
condition:
lambda: return (klappe == 1);
then:
- switch.turn_on: klappe_select
else:
- switch.turn_off: klappe_select
- if:
condition:
lambda: return open ;
then:
- switch.turn_on: klappen_open
else:
- switch.turn_off: klappen_open
- switch.turn_on: klappen_power
- delay: 8s
- switch.turn_off: klappen_power
- switch.turn_off: klappen_open
- switch.turn_off: klappe_select
so the assumption is that queuing will take care of the locking.
This works when done separately/manually waiting in between…
But when I want/need to open or close at the same time it fails - only one cover is opened/closed in the real world while the other stays the same.
Here an example when a fan needs to open/close the covers when started/stopped:
fan:
- id: !extend fan_abluft
on_turn_on:
then:
- cover.open: klappe_oben
- cover.open: klappe_unten
on_turn_off:
then:
- cover.close: klappe_oben
- cover.close: klappe_unten
the only thing that seems to work is when I add an explicit delay in between the cover.open/close - like this
- cover.open: klappe_oben
- delay: 10s
- cover.open: klappe_unten
Is there one of the expectations of mine arround queued scripts wrong?
Is there a different way to implement a mutex?
Did I miss something?