I have been playing with this for a couple of days now and its testing me…
I am really new to Home Assistant, but i always like to give it ago. I have a aftermarket hot tub controller that can be controlled via a web interface, i have ran a packet capture to find the commands it needs to write settings to the unit, that i have working just fine. What i am struggling with is to read the JSON and use the result in an if else scenario.
The JSON i get back from the unit is:
{ "temperature": 31, "waterpump": 1, "temperature_set": 38, "airpump": 0, "heaters": 0, "heater1": 0, "heater2": 0, "override": 130, "errorcode": "NONE", "last_swser1": "0", "last_swser2": "0", "or_waterpump": "2", "or_heater": "0", "code_ver": "10.5", "ssid": "Area12", "autoupdate": "1", "autoreboot": "1", "hwversion": "3", "sendreceive": "1", "mqttdestination": "0.0.0.0", "mqttuser": "secretuser", "mqttpass": "secret", "homeassistant": "0.0.0.0", "discovery_mode": "0", "or_air": "0" }
I am using the following Rest sensor:
- platform: rest
name: hottub_controller
resource_template: http://192.168.10.167/stat
timeout: 15
scan_interval: 60
json_attributes:
- temperature
- temperature_set
- waterpump
- heaters
- airpump
value_template: "OK"
- platform: template
sensors:
hottub_current_temp:
value_template: '{{ states.sensor.hottub_controller.attributes["temperature"] }}'
device_class: temperature
unit_of_measurement: "°C"
friendly_name: "Current Temp"
hottub_target_temp:
value_template: '{{ states.sensor.hottub_controller.attributes["temperature_set"] }}'
device_class: temperature
unit_of_measurement: "°C"
friendly_name: "Target Temp"
hottub_filter_pump:
friendly_name: "Filter Pump"
value_template: >
{% if (states('sensor.hottub_controller.attributes["waterpump"]')) == "0" %}
Off
{% elif (states('sensor.hottub_controller.attributes["waterpump"]')) == "1" %}
On
{% else %}
Unknown
{% endif %}
I can read the JSON and display the results with the first two sensors, the issue i have is that teh hottub_filter_pump sensor wont use the result of a 0 or 1 and then print yes if its a 1 or no if its a 0.
What am i missing?