I have a multiple rest sensor working but I need to convert some returned numbers into the strings they represent. For example the sensor state
is returning 1 or 0 but I would like to display this as On
or Off
.
I’ve been trying for hours without success.
- platform: rest
name: JSON Lounge Aircon
json_attributes:
- state
- mode
- temp
- fan
- aux
- roomt
resource: http://10.1.1.9/json
- platform: template
sensors:
state:
friendly_name: 'State'
value_template: >
{% if is_state('{{ states.sensor.json_lounge_aircon.attributes["mode"] }}' '0' ) %}
'Off'
{% elif is_state('{{ states.sensor.json_lounge_aircon.attributes["mode"] }}' '1' ) %}
'On'
{% endif %}
mode:
friendly_name: 'Mode'
value_template: '{{ states.sensor.json_lounge_aircon.attributes["mode"] }}'
temp:
friendly_name: 'Set Temperature'
value_template: '{{ states.sensor.json_lounge_aircon.attributes["temp"] }}'
fan:
friendly_name: 'Fan mode'
value_template: '{{ states.sensor.json_lounge_aircon.attributes["fan"] }}'
aux:
friendly_name: 'Power mode'
value_template: '{{ states.sensor.json_lounge_aircon.attributes["aux"] }}'
roomt:
friendly_name: 'Current Temperature'
value_template: '{{ states.sensor.json_lounge_aircon.attributes["roomt"] | round(1) }}'
unit_of_measurement: "°C"