ha_epex_spot
ha_epex_spot copied to clipboard
Different service call results depending on where the service is called.
I'm trying to determine the start of the lowest price interval, based on the epex_spot.get_lowest_price_interval
service call.
If I use this service call in the Developers tools:
service: epex_spot.get_lowest_price_interval
data:
duration:
hours: 3
earliest_start: "07:00:00"
latest_end: "16:00:00"
I get this response:
start: "2024-03-29T12:00:00+01:00"
end: "2024-03-29T15:00:00+01:00"
price_eur_per_mwh: 12.09
price_ct_per_kwh: 1.209
net_price_ct_per_kwh: 1.209
12:00 in localized time is correct!
But when I use the service call like this, in the config-file:
- trigger:
- platform: time
at: 00:00:01
action:
- service: epex_spot.get_lowest_price_interval
data:
duration:
hours: 2
earliest_start: "07:00:00"
latest_end: "16:00:00"
response_variable: resp
sensor:
- name: start_laagste_prijs
device_class: timestamp
state: "{{ resp.start is defined and resp.start }}"
Then the sensor.start_laagste_prijs
gets a different value, that is wrong.
2 observations:
- You have a duration of 3h in the developer tools and 2h in the config file.
- 2024-03-29T12:00:00+01:00 represents the same point in time as 2024-03-29T11:00:00+00:00. The first is timestamp includes a timezone offset of 1h which causes the difference.
HA displays timestamps in the entity status view with UTC timestamp (= timezone offset 0). But the timestamp is correct and if you display the sensor value in Lovelace (e.g. an entity card), it will also use your local timezone.
Any feedback on this?
I changed my Apex data generator as follows. This now seems to render the right result:
data_generator: >
return entity.attributes.data.map((entry, index) => { return [new
Date(entry.start_time).getTime(), ((0.2040 + entry.price_ct_per_kwh) *
1.06 ) + (1.582+4.71756+0.20417+5.03288)]; }).slice(new
Date(hass.states['sensor.start_laagste_prijs'].state).getHours(),new
Date(hass.states['sensor.start_laagste_prijs'].state).getHours()+3);