I’ve searched all over on this forum and other forums, but I can’t get it to work properly, so I need your help
I use EnergyZero’s HACS integration and it works well. This retrieves gas prices and electricity prices from the EnergyZero API. This is used by a number of dynamic energy providers in the Netherlands.
Sometimes it can happen that the new gas price is not available in the morning at 6 o’clock. As a result, there are big gaps in my gas prices, so the energy dashboard doesn’t give the correct totals for my gas usage.
Okay, that looks promising. One more question then: I now have all my sensors (including the template sensors) in the sensors.yaml.
But I suspect that your piece of code doesn’t belong there, is that right?
Correct, the sensors.yaml file likely has a top level configuration variable “sensor”, for the new format the top level variable needs to be “template”. There are a few different ways to include files in your configuration. The basic method is just to have all the template entities in one file. Personally, I prefer using packages
Unfortunately, it still doesn’t work flawlessly…
Firstly, I have the problem that it stays empty after a restart of HA, which is strange because the sensor then also gets an update.
Second, the template sensor is currently empty, while the real sensor does have a value and that shouldn’t happen if I’m right.
The code I’m using now is as follows:
template:
- trigger:
- platform: state
entity_id: sensor.energyzero_today_gas_current_hour_price
not_to: ["unavailable", "unknown"]
sensor:
- name: Gasprice Incl
state: >
{% set gas = trigger.to_state.state | float(0) + 0.6754 %}
{% if gas > 0 %} {{ gas }}
{% else %} {{ states('sensor.gasprice_incl') }}
{% endif %}
unique_id: sensor.gasprice_incl
unit_of_measurement: "EUR/m³"
The real sensor has a big gap again, like every morning between +/- 06:00 and +/- 08:30. But the template sensor remains Unknown.
Could it be a case sensitive problem? I don’t know which values are exactly ‘unknown’ or ‘unavailable’.