I can get the template to work on the template debugger, but it won’t work when I plug it in to my script.
I have a mqtt topic that works as a variable for the lux setting on my hue lamp. The template is supposed to change topic value based on the time or set the topic value to what ever the hue-hub lamp value was last.
lux_set:
- service: mqtt.publish
data:
topic: "light"
payload_template: >
{% if states.sensor.time.state.split(":")[0] >= "20" %}
25
{% elif states.sensor.time.state.split(":")[0] >= "08" %}
255
{% else %}
'{{states.sensor.hue_lvngrm_lamp_brightness.state }}'
{% endif %}
qos: 1
This is the error on the log
17-03-16 02:13:42 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [script]: expected a dictionary for dictionary value @ data[‘script’][‘lux_set’]. Got [OrderedDict([(‘service’, ‘mqtt.publish’), (‘data’, OrderedDict([(‘topic’, ‘light’), (‘payload_template’, ‘{% if states.sensor.time.state.split(“:”)[0] >= “20” %}\n 25 \n{% elif states.sensor.time.state.split(“:”)[0] >= “08” %}\n 255\n{% else %}\n '{{states.sensor.hue_lvngrm_lamp_brightness.state }}'\n{% endif %}\n’), (‘qos’, 1)]))])]. (See /home/homeassistant/.homeassistant/configuration.yaml, line 337). Please check the docs at Scripts - Home Assistant