The above works in the template renderer, but I get an error on validating the config.
Error loading /config/configuration.yaml: while scanning for the next token
found character '%' that cannot start any token
in "/config/automations.yaml", line 25, column 8
That post isnāt a solution, that template wonāt work. If the binary sensor is off it will spit out one long string, not the ordered dict you actually need.
Also, you didnāt need all the minus signs, the second one validates in the config checker because you indented the template by 2 spaces, but on the first one you didnāt.
@kiwijunglist Iām trying to do a similar thing with the mqtt.publish command but am getting the same config error; found character ā%ā that cannot start any token
- alias: Entry Door status via MQTT
hide_entity: true
trigger:
platform: state
entity_id: binary_sensor.entry_door_w
action:
service: mqtt.publish
data:
topic: "entry_door/status"
payload_template: {%- if is_state("binary_sensor.entry_door_w", "off") -%}Closed{%- else -%}Open{%- endif -%}
retain: false
Iāve tried by template in the developer console using the dev-mqtt page and it works. I added the minus signs by the % symbols but it made no difference. Any feedback would be appreciated.
Note that the first quote mark Iāve changed is immediately before a percent sign? Thatās why the error was talking about the percent sign, because the way you had it it read the first " then started reading the template, then got to the second " and stopped, and then it found a percent sign it wasnāt expecting.
Now when it reads the template it will get all of it because that is all there is between the double quotes.
I want to have the entityās service change depending on its state. If itās on to call the service turn_off and viceversa.
The if statement works in the template editor but it doesnt when i apply it in the ui-lovelace.yaml.
What is wrong?