I am trying to create an automation that will keep firing until an RF controlled fan is off or on. I’ve tried this with both “states” and “is_state” in the conditions. But it seems like no matter what I do it only runs once and I could use some help. Thanks.
Does the MQTT command change the state of the triggering binary sensor?
That would cancel and restart the automation since you are using restart mode will retrigger… which seems like it might create a loop.
You can simplify your until condition using tuple comparison:
I just tried your code without success. The MQTT command is sending the RF signal to turn the light on or off. Which I don’t think is affecting the Until statement. Unfortunately, it is the same signal “16774171” for both. “16774172” is a dummy code which does trigger “16774171” elsewhere and I will include my full code at the bottom. This has been the challenge all along with this project. I want to double check the fan states based on the watt reading I am getting from the Shelly 2.5 I have attached to the fan switch.
THIS IS THE EXACT DUMBED DOWN CODE I JUST TRIED IN AN EFFORT TO ISOLATE
- alias: Samuel's Ceiling Fan Light
trigger:
- platform: state
entity_id:
- binary_sensor.samuel_ceiling_fan_light_input
# state of wall switch on/off
id: wall_switch
- platform: state
entity_id:
- counter.samuel_fan_light
id: light_state
action:
- choose:
- conditions:
- condition: trigger
id: wall_switch
sequence:
- repeat:
until:
condition: template
value_template: >
{{ ( states('binary_sensor.samuel_ceiling_fan_light_input'), states('binary_sensor.samuel_s_ceiling_fan_light_wattage') ) in [('on' ,'on'), ('off', 'off')] }}
# checking whether the wall switch is on/ff and the light is on based on watt reading
sequence:
- service: mqtt.publish
data:
topic: "home/OpenMQTTGateway/commands/MQTTto433"
payload_template: >-
{% if states('binary_sensor.samuel_ceiling_fan_light_input') == 'on' %}
#wall switch on
{"value":16774171,"protocol":11,"length":24,"delay":385, "repeat": 10}
{% elif states('binary_sensor.samuel_ceiling_fan_light_input') == 'off' %}
#wall switch off
{"value":16774172,"protocol":11,"length":24,"delay":385, "repeat": 5}
{% else %}
{"value":Samuel Light Switch ERROR}
{% endif %}
- delay:
seconds: 4
After doing a lot of experimenting it seems the “payload_template: >-” is causing the problem. I am just not sure what the statement is not liking to only fire once.
So it does look like another trigger in the automation is restarting everything like you said. If I run the repeat part of the automation in a script I assume this will alleviate the problem?