@SylvainGa wrote:
Probably through AppDaemon but I haven’t learned how to use it yet but until then, is there a better way of doing the following in scripts?
I have a fan that I control through a Tasmota device. It has one push button that goes from High, Medium, Low, Off (in that order) and the Tasmota device toggles de button for 0.5 sec. I defined an input_number variable called ventilateur_salon_speed and 4 scripts. This is the script for Max speed but they are the same, except the number they stop at (0 for Off, 1 for Low, 2 for Medium and 3 for High). The script goes through 3 main actions: Test if already at its required value and if it is, stop the script. If not, turn on the button and decrement the variable. If it reaches 0, start back at 3 then delay so it has time to toggle before continuing. Since it can take 3 iterations (ie, push the button 3 times) to reach the requested speed, it repeat this action 3 times (hence why 3 main actions).
'1586725146435': alias: VentilateurSalonSpeedMax sequence: - condition: template value_template: > {% if states.input_number.ventilateur_salon_speed.state | float == 3.0 %}false{% else %}true{% endif %} - data: {} entity_id: switch.ventilateursalonalimentation service: switch.turn_on - data_template: value: '{% if states.input_number.ventilateur_salon_speed.state | float < 1.0 %}3.0{% else %}{{ states.input_number.ventilateur_salon_speed.state | float - 1.0 }}{% endif %}' entity_id: input_number.ventilateur_salon_speed service: input_number.set_value - condition: template value_template: > {% if states.input_number.ventilateur_salon_speed.state | float == 3.0 %}false{% else %}true{% endif %} - delay: 00:00:01 - data: {} entity_id: switch.ventilateursalonalimentation service: switch.turn_on - data_template: value: '{% if states.input_number.ventilateur_salon_speed.state | float < 1.0 %}3.0{% else %}{{ states.input_number.ventilateur_salon_speed.state | float - 1.0 }}{% endif %}' entity_id: input_number.ventilateur_salon_speed service: input_number.set_value - condition: template value_template: > {% if states.input_number.ventilateur_salon_speed.state | float == 3.0 %}false{% else %}true{% endif %} - delay: 00:00:01 - data: {} entity_id: switch.ventilateursalonalimentation service: switch.turn_on - data_template: value: '{% if states.input_number.ventilateur_salon_speed.state | float < 1.0 %}3.0{% else %}{{ states.input_number.ventilateur_salon_speed.state | float - 1.0 }}{% endif %}' entity_id: input_number.ventilateur_salon_speed service: input_number.set_value
What do you think? Can you improve it? Make it more efficient or fix possible pitfalls?
Edit : forgot to say the scripts are called by Alexa.
Thanks.
Posts: 1
Participants: 1