I’m trying to connect a P1 sensor to Home Assistant. I’ve edited the yaml files as described below but I cannot find any entity related to the sensor whatever I seem to do in HA. In short:
- the local API works fine and gives JSON
- Nothing shows up in Home Assistant
Based on earlier Q&As on this forum that seem related I’ve tried a couple of changes to the yaml configuration, with no result.
What am I missing, where should I start?
Setup
- HA runs in a docker container on a Synology NAS.
- The sensor data is exposed via an API at http://p1-dongle-pro.local/api/v2/sm/actual
- As a check to see if the container has access to the API I ran in the terminal on the docker container:
curl -X GET http://p1-dongle-pro.local/api/v2/sm/actual
, which does not work . It gets aCould Not Resolve host:
- But
curl -X GET http://p1-dongle-pro.local/api/v2/sm/actual
does work in the terminal on a local laptop and gives a JSON response:
{"timestamp":{"value":"231017084723S"},"energy_delivered_tariff1":{"value":9437.085,"unit":"kWh"},"energy_delivered_tariff2":{"value":11350.049,"unit":"kWh"},"energy_returned_tariff1":{"value":898.278,"unit":"kWh"},"energy_returned_tariff2":{"value":1962.837,"unit":"kWh"},"electricity_tariff":{"value":"0002"},"power_delivered":{"value":0.214,"unit":"kW"},"power_returned":{"value":0,"unit":"kW"},"voltage_l1":{"value":232,"unit":"V"},"current_l1":{"value":1,"unit":"A"},"power_delivered_l1":{"value":0.214,"unit":"kW"},"power_returned_l1":{"value":0,"unit":"kW"},"gas_delivered":{"value":6161.766,"unit":"m3"},"gas_delivered_timestamp":{"value":"231017084510S"},"water":{"value":0.001,"unit":"m3"}}
- configuration.yaml has:
rest: !include rest.yaml
- and rest.yaml looks like this:
- resource: http://p1-dongle-pro.local/api/v2/sm/actual
scan_interval: 10
sensor:
- name: P1 LastUpdate
value_template: "{{ as_local(strptime(value_json.timestamp.value[0:12], '%y%m%d%H%M%S')) }}"
device_class: "Timestamp"
unique_id: p1-lastupdate
- name: P1 Energy Consumption Tariff 1
value_template: "{{ value_json.energy_delivered_tariff1.value | float }}"
device_class: "energy"
state_class: "total_increasing"
unit_of_measurement: "kWh"
unique_id: p1-t1
- name: P1 Energy Consumption Tariff 2
value_template: "{{ value_json.energy_delivered_tariff2.value | float }}"
device_class: "energy"
unit_of_measurement: "kWh"
state_class: "total_increasing"
unique_id: p1-t2
- name: P1 Energy Returned Tariff 1
value_template: "{{ value_json.energy_returned_tariff1.value | float }}"
device_class: "energy"
unit_of_measurement: "kWh"
state_class: "total_increasing"
unique_id: p1-rt1
- name: P1 Energy Returned Tariff 2
value_template: "{{ value_json.energy_returned_tariff2.value | float }}"
device_class: "energy"
unit_of_measurement: "kWh"
state_class: "total_increasing"
unique_id: p1-rt2
- name: P1 Power Consumption Actual Total
value_template: "{{ value_json.power_delivered.value | float }}"
device_class: "power"
unit_of_measurement: "kW"
unique_id: p1-pt
- name: P1 Power Returned Actual Total
value_template: "{{ value_json.power_returned.value | float }}"
device_class: "power"
unit_of_measurement: "kW"
unique_id: p1-prt
- name: P1 Voltage Phase 1
value_template: "{{ value_json.voltage_l1.value | float }}"
device_class: "voltage"
unit_of_measurement: "V"
unique_id: p1-v1
- name: P1 Voltage Phase 2
value_template: "{{ value_json.voltage_l2.value | float }}"
device_class: "voltage"
unit_of_measurement: "V"
unique_id: p1-v2
- name: P1 Voltage Phase 3
value_template: "{{ value_json.voltage_l3.value | float }}"
device_class: "voltage"
unit_of_measurement: "V"
unique_id: p1-v3
- name: P1 Current Phase 1
value_template: "{{ value_json.current_l1.value | float }}"
device_class: "current"
unit_of_measurement: "A"
unique_id: p1-a1
- name: P1 Current Phase 2
value_template: "{{ value_json.current_l2.value | float }}"
device_class: "current"
unit_of_measurement: "A"
unique_id: p1-a2
- name: P1 Current Phase 3
value_template: "{{ value_json.current_l3.value | float }}"
device_class: "current"
unit_of_measurement: "A"
unique_id: p1-a3
- name: P1 Power Consumption Phase 1
value_template: "{{ value_json.power_delivered_l1.value | float }}"
device_class: "power"
unit_of_measurement: "kW"
unique_id: p1-p1
- name: P1 Power Consumption Phase 2
value_template: "{{ value_json.power_delivered_l2.value | float }}"
device_class: "power"
unit_of_measurement: "kW"
unique_id: p1-p2
- name: P1 Power Consumption Phase 3
value_template: "{{ value_json.power_delivered_l3.value | float }}"
device_class: "power"
unit_of_measurement: "kW"
unique_id: p1-p3
- name: P1 Power Returned Phase 1
value_template: "{{ value_json.power_returned_l1.value | float }}"
device_class: "power"
unit_of_measurement: "kW"
unique_id: p1-pr1
- name: P1 Power Returned Phase 2
value_template: "{{ value_json.power_returned_l2.value | float }}"
device_class: "power"
unit_of_measurement: "kW"
unique_id: p1-pr2
- name: P1 Power Returned Phase 3
value_template: "{{ value_json.power_returned_l3.value | float }}"
device_class: "power"
unit_of_measurement: "kW"
unique_id: p1-pr3
- name: P1 Gas Consumption
value_template: "{{ value_json.gas_delivered.value | float }}"
device_class: "gas"
state_class: "total_increasing"
unit_of_measurement: "m³"
unique_id: p1-gas
- name: P1 Water Consumption
value_template: "{{ value_json.water.value | float }}"
device_class: "water"
state_class: "total_increasing"
unit_of_measurement: "m³"
unique_id: p1-water