T3m3z / spotprices2ha

Simple copy-paste approach to fetch data from api.spot-hinta.fi (see https://spot-hinta.fi) to Home Assistant. Includes simple sensors and UI elements to ease automation work.
MIT License
111 stars 14 forks source link

Night time price (SHF Price2) not working even though times are set #22

Closed Sappher closed 1 year ago

Sappher commented 1 year ago

Hi, and firstly, thank you a great sensor package!

I'm quite new to HA but I've gotten used to the basics and with these sensors I've gotten great tools for different automations. However, it seems like the calculation for night time electricity transfer fees isn't working.

I have set up the variables: image

But it always just uses the Price1 value, even if time is between 22:00 and 07:00: image image image

I've tried with version 0.11.1 and just updated to 0.2.0 but it still has the same issue.

Sappher commented 1 year ago

I took a look at the code for shf_data and it seems like I needed to input the prices other way around: Price1 for night time prices and Price2 for daytime prices. This is because it compares the values as hours and of course in my setup the day changes (between times 22 and 07), making the compare not really valid. I coudln't figure out a clean way to make the compare take this in account either so I just changed the mirrorred the values and it works fine now because day time transfer fee is within a day period (7-22).

So I think this can be closed, maybe update the documentation or if you do find a way to make a reliable compare code - even better!

T3m3z commented 1 year ago

Great that you found the solution. I added a small section about the correct way of configuring this to the readme file.

T3m3z commented 1 year ago

And version 0.2.1 now contains validation so that you cannot set the Price2 start/stop wrong way (stop being before start). That should help or at least gently push users into correct direction.