Works really good so far. Unfortunately, the device will check for updates only every five minutes. And send updates (through MQTT) only then. So the state of the switch will go back to “off” on the GUI after a couple of seconds (because the device itself stays in “off”). Only when the device checks for new commands it will update the state.
Do I have a change to set the state somehow manually until the next scheduled update?
The state of the switch (an its update frequency) comes from sensor.r_wp, not from the switch itself.
You could use an intermediary input_boolean helper to mitigate the slow updates (set it to true/false in turn_on/turn_off, and also on the update of sensor.r_wp)
Then I created two automations (only shown the “on” version):
alias: Helper E_Hzg (on)
description: ""
triggers:
- trigger: state
entity_id:
- sensor.r_ehzg
from: "off"
to: "on"
conditions: []
actions:
- action: input_boolean.turn_off
target:
entity_id: input_boolean.helper_ehzg
data: {}
mode: single
What I get from these are two “switches” on the gui where I can enable or disable the device in question.
When setting the switch helper to “on”, it sends the MQTT message but nothing happens to the boolean helper (of course, because the sensor has not changed its state due to 5min delay).
When using the boolean helper to switch, the switch helper immediately follows the setting of the boolean helper regarding its state. But it does not send the MQTT messages …
I do not mind using only one of these two on the dashboard but it should follow the other…
From my understanding it would be perfect if I could configure an additional action to my mqtt switch which sets the boolean helper to on or off. But as far as I understand I can only have a single action there.
[Update-Edit] Seems to work with the spaces removed before “on” and “off”. Updated to document a working example.
Ok, thanks for clarification. I tried it now with a single automation.
Expected behaviour is on a state change of the sensor to start an according (on or off) action to set the helper, too.
But, getting errors
lias: Helper E_Hzg Status
description: ""
triggers:
- trigger: state
entity_id:
- sensor.r_ehzg
to: null
conditions: []
actions:
- action: >-
input_boolean.turn_{% if(trigger.state == '1') %}on{% else %}off{%
endif %}
target:
entity_id: input_boolean.helper_ehzg
data: {}
mode: single
Getting error when executing the automation: Template rendered invalid service: input_boolean.turn_ off