sernafa
(Sergio Navarro Fajardo)
December 10, 2019, 12:18pm
1
Hi, I need some help with configuring this senson with rest and value_template. In my configuration.yml file:
- platform: rest
resource: http://localhost:3000/api/v1/hvac
json_attributes:
- data
name: airzone
method: POST
payload: '{"systemID":1,"zoneID":0}'
scan_interval: 60
value_template: 'OK'
- platform: template
sensors:
blueface_status:
friendly_name: Status
value_template: {{ states.sensor.airzone.attributes.data.0.on }}
{{ states.sensor.airzone.attributes.data.0.on }} show values 0 or 1, depending on the operating status. It’s ok.
Is it possible to use an ‘if’, as an example although it is incorrect, to be able to show “running -> 1” and “stopped -> 0”?
Ex:
value_template: >-
--> {% if {{ states.sensor.airzone.attributes.data.0.on }} == '1' %} <--
Running
{% else %}
Stopped
{% endif %}
Thks in advance.
Cyn you please show how the sensor looks like in the states page?
Try like this:
value_template: >-
{% if state_attr('sensor.airzone', 'data')['0']['on'] == 1 %}
Running
{% else %}
Stopped
{% endif %}
sernafa
(Sergio Navarro Fajardo)
December 10, 2019, 3:06pm
3
First thanks for your reply.
I have done the test and it does not work. Do you mean json as an example?
{
"data": [{
"systemID": 1,
"zoneID": 1,
"on": 1,
"maxTemp": 30,
"minTemp": 15,
"setpoint": 20.500000,
"roomTemp": 23.100000,
"modes": [1, 1, 4, 2, 3, 5],
"mode": 3,
"coldStages": 1,
"coldStage": 1,
"heatStages": 2,
"heatStage": 2,
"humidity": 61,
"units": 0,
"errors": []
}, {
"systemID": 1,
"zoneID": 7,
"on": 0,
"maxTemp": 30,
"minTemp": 15,
"setpoint": 23,
"roomTemp": 21.100000,
"coldStages": 0,
"coldStage": 0,
"heatStages": 2,
"heatStage": 2,
"humidity": 67,
"units": 0,
"errors": []
}]
}
Thks again!
No I mean the sensor.airzone when you go to Developer Tools -> States.
Try with removing the single quotes around the 0, I assumed 0 was the name of the dict.
value_template: >-
{% if state_attr('sensor.airzone', 'data')[0]['on'] == 1 %}
Running
{% else %}
Stopped
{% endif %}
petro
(Petro)
December 10, 2019, 6:06pm
5
try
value_template: >
{% set v = states.sensor.airzone.attributes.data[0].on %}
{% set n = 'Running' if v else 'Stopped' %}
{{ n }} -> {{ v }}
sernafa
(Sergio Navarro Fajardo)
December 11, 2019, 6:11am
6
Burningstone:
sensor.airzone
Hi again,
Your code works ok!! Great!!
As you told me:
data:
- systemID: 1
zoneID: 1
'on': 1
maxTemp: 30
minTemp: 15
setpoint: 20.5
roomTemp: 20.9
modes:
- 1
- 1
- 4
- 2
- 3
- 5
mode: 3
coldStages: 1
coldStage: 1
heatStages: 2
heatStage: 2
humidity: 57
units: 0
errors: []
- systemID: 1
zoneID: 2
'on': 0
maxTemp: 30
minTemp: 15
setpoint: 24.5
roomTemp: 19.799999
coldStages: 1
coldStage: 1
heatStages: 2
heatStage: 2
humidity: 64
units: 0
errors: []
- systemID: 1
zoneID: 3
'on': 0
maxTemp: 30
minTemp: 15
setpoint: 21.5
roomTemp: 21.299999
coldStages: 1
coldStage: 1
heatStages: 2
heatStage: 2
humidity: 60
units: 0
errors: []
- systemID: 1
zoneID: 4
'on': 0
maxTemp: 30
minTemp: 15
setpoint: 21.5
roomTemp: 20.5
coldStages: 1
coldStage: 1
heatStages: 2
heatStage: 2
humidity: 61
units: 0
errors: []
- systemID: 1
zoneID: 5
'on': 0
maxTemp: 30
minTemp: 15
setpoint: 19.5
roomTemp: 19.5
coldStages: 1
coldStage: 1
heatStages: 2
heatStage: 2
humidity: 69
units: 0
errors: []
- systemID: 1
zoneID: 6
'on': 0
maxTemp: 30
minTemp: 15
setpoint: 23
roomTemp: 18.9
coldStages: 1
coldStage: 1
heatStages: 2
heatStage: 2
humidity: 69
units: 0
errors: []
- systemID: 1
zoneID: 7
'on': 0
maxTemp: 30
minTemp: 15
setpoint: 23
roomTemp: 18.200001
coldStages: 0
coldStage: 0
heatStages: 2
heatStage: 2
humidity: 70
units: 0
errors: []
friendly_name: airzone
But now, works ok.
Thks a lot Burningstone!!
sernafa
(Sergio Navarro Fajardo)
December 11, 2019, 6:19am
7
Hi Petro!
Thks in advance! I have already try to put your code, and functions ok!
Thks a lot!
Glad that it works now
Please mark the post that helped you find the solution. This way others can easier find the solution in the future.