hi,
I have recently started with Home Assistant, and look for some advice on my config.
I have an (old) Rpi with serial connection to a P1 interface, and I have made the data accessible via Nginx to use the ‘Rest’ interface:
$ curl -s http://192.168.1.9/ha/p1_file.json | jq
{
"p1": {
"gas": 5463.987,
"low": 6451478,
"high": 6170272,
"ret_low": 842.126,
"ret_high": 2234.51
}
}
I would like to only query the API Server once, but I am unable to get the gathered data selectable as energy sensors in the Energy dashboard. The sensors do show up, and gather historical data (all good), but they are not presented in the Energy dashboard selection menu.
See below my 2 configs, whereby the 1st one works OK in HA (can select in Energy dashboard), but it requires more API call:
sensor:
- platform: rest
resource: http://192.168.1.9/ha/p1_file.json
name: low
value_template: '{{ value_json.p1.low }}'
device_class: energy
state_class: total_increasing
unit_of_measurement: "Wh"
scan_interval: 60
- platform: rest
resource: http://192.168.1.9/ha/p1_file.json
name: high
value_template: '{{ value_json.p1.high }}'
device_class: energy
state_class: total_increasing
unit_of_measurement: "Wh"
scan_interval: 60
- platform: rest
resource: http://192.168.1.9/ha/p1_file.json
name: ret_low
value_template: '{{ value_json.p1.ret_low }}'
device_class: energy
state_class: total_increasing
unit_of_measurement: "Wh"
scan_interval: 60
- platform: rest
resource: http://192.168.1.9/ha/p1_file.json
name: ret_high
value_template: '{{ value_json.p1.ret_high }}'
device_class: energy
state_class: total_increasing
unit_of_measurement: "Wh"
scan_interval: 60
- platform: rest
resource: http://192.168.1.9/ha/p1_file.json
name: gas
value_template: '{{ value_json.p1.gas }}'
device_class: gas
state_class: total_increasing
unit_of_measurement: "m³"
scan_interval: 60
This is my more ‘smart’ config, but with this in place, I cannot select the sensors:
sensor:
- platform: rest
name: p1
resource: http://192.168.1.9/ha/p1_file.json
scan_interval: 60
force_update: true
json_attributes:
- p1
value_template: "OK"
state_class: total_increasing
- platform: template
sensors:
p1_high:
value_template: "{{ state_attr('sensor.p1', 'p1')['high'] }}"
device_class: energy
unit_of_measurement: "KWh"
p1_low:
value_template: "{{ state_attr('sensor.p1', 'p1')['low'] }}"
device_class: energy
unit_of_measurement: "KWh"
p1_gas:
value_template: "{{ state_attr('sensor.p1', 'p1')['gas'] }}"
device_class: gas
unit_of_measurement: "m³"
p1_ret_high:
value_template: "{{ state_attr('sensor.p1', 'p1')['ret_high'] }}"
device_class: energy
unit_of_measurement: "KWh"
p1_ret_low:
value_template: "{{ state_attr('sensor.p1', 'p1')['ret_low'] }}"
device_class: energy
unit_of_measurement: "KWh"
I must be overlooking something silly?
Help is greatly appreciated!