Please format your code correctly, using the </> button. With it formatted like that, I cannot copy-paste it for experimentation without fixing it first.
Your REST sensor json_attributes
setup is wrong, because heatpump
is a list not a dict. Even if that had worked, your (legacy-format) template sensors are looking for non-existent attributes called '1'
and '2'
.
As a better alternative to a REST sensor and a pair of template sensors, try this RESTful integration setup, under rest:
not under sensor:
(and you’ll need a full restart if this is your first rest:
entry):
rest:
- resource: http://192.168.1.193/json
scan_interval: 60
binary_sensor:
- name: "Heatpump State"
value_template: >
{{ value_json['heatpump']
|selectattr('Name','eq','Heatpump_State')
|map(attribute='Value')|first == '1' }}
device_class: running
sensor:
- name: "Force DHW State"
value_template: >
{{ value_json['heatpump']
|selectattr('Name','eq','Force_DHW_State')
|map(attribute='Value')|first }}
- name: "Pump Flow"
value_template: >
{{ value_json['heatpump']
|selectattr('Name','eq','Pump_Flow')
|map(attribute='Value')|first }}
unit_of_measurement: "L/min"
device_class: volume_flow_rate
Consider whether the “Force DHW State” should also be a binary sensor. I don’t know the details of what it represents to be able to make that judgement, although I did for the Status one…
Testing those templates after cleaning up your unformatted code:
{% set value_json = {"heatpump":
[ {"Topic": "TOP0","Name": "Heatpump_State","Value": "1","Description": "On"},
{"Topic": "TOP1","Name": "Pump_Flow","Value": "0.13","Description": "l/min"},
{"Topic": "TOP2","Name": "Force_DHW_State","Value": "0","Description": "Disabled"},
] } %}
Force DHW state: {{ value_json['heatpump']|selectattr('Name','eq','Force_DHW_State')|map(attribute='Value')|first }}
Pump Flow: {{ value_json['heatpump']|selectattr('Name','eq','Pump_Flow')|map(attribute='Value')|first }}
Status: {{ value_json['heatpump']|selectattr('Name','eq','Heatpump_State')|map(attribute='Value')|first == '1' }}