Hi yaml wizards!
I have a working automation that sends entity state changes to a rest api.
See below for the full automation.
The question is about this part:
parameter: >-
HA {{ trigger.entity_id }}/{% set state = trigger.to_state.state %}{%
if state == "on" %}{% set state = "1" %}{% elif state == "off" %}{% set
state = "0" %}{% endif %}{{state}}
What is does is building up the parameter of the REST url.
It converts the string in trigger.to_state.state to 1 if it is “on” and to 0 if it is “on”. Else it passes the string as is.
This works as intended, but it is quite unreadable by a human. Or at least by me
My question is: How can I rewrite this in a more cleaner/readable way?
For context, here is the whole automation:
alias: Home Assistant to Loxone
description: ''
trigger:
- platform: state
entity_id:
- sensor.exhaust_fan_duty
- media_player.radio
- binary_sensor.aqara_washing_machine_sensor_contact
- sensor.esphome_web_600e0b_boiler_return_temperature
- sensor.esphome_web_600e0b_boiler_outlet_temperature_2
- sensor.esphome_web_a6982c_co2_value
- sensor.hue_remote_bathroom_action
- input_select.ha_shading_controller
- sensor.sk1_hall_motion
condition: []
action:
- service: rest_command.update_loxone
data:
parameter: >-
HA {{ trigger.entity_id }}/{% set state = trigger.to_state.state %}{%
if state == "on" %}{% set state = "1" %}{% elif state == "off" %}{% set
state = "0" %}{% endif %}{{state}}
mode: parallel
id: '1703699168468'
A link to some docs covering this are also welcome!
Thanks!
Gert