I am trying to create one automation to handle two different events. Reason is that I want to put one single switch on the GUI to turn it off and on for the end-user. The automation should only be running when the user selects it. The hard thing is that I want two different states to change the service usesd in the action.
This does not work but I guess you get the idea. If sensor.ladenivå is below 75 then action service.turn_on and if it is above 80 then action service.turn_off. Is this even possible? Seems the declaration of the variabel “action” does not fly well. Could I save the state in a template perhaps? Any ideas?
Here is the error from config validation:
Invalid config for [automation]: Service {% if action == “on” %} switch.turn_on {% elif action == “off” %} switch.turn_off {% endif %} does not match format . for dictionary value @ data[‘action’][0][‘service’]. Got None invalid template (TemplateSyntaxError: expected token ‘end of statement block’, got ‘action’) for dictionary value @ data[‘trigger’][0][‘value_template’]. Got None
I don’t think you can define local variables that way in the value_template; that whole if statement looks like invalid python to me.
Why not use two state triggers - one that fires when the sensor value is below 75 and the other above 80, so something like:
Yes, thanks for this. Might be a good idea but I think I will need to duplicate the states(“sensor.ladeniva”) | int since the state is not integer. … let me test!
If anyone has more ideas please share but I will test this as soon as I get off work.