I am sorry for the late reply, I was not able to sit down with this yesterday. The reason for me to store it is to make sure the charger starts even if the Nordpool integration goes down.
Your code works, which is great, but it returns the original time, which is one hour earlier than I need. I can find a work-around for that, but it would be nice to have it correct from the start. Maybe that’s not possible?
I’m not sure if I understood when you said “original time”. When I see your screenshot I see the time is shown on UTC, but that shouldn’t be an issue as HA will handle the timezone for you and will show on the front end with your timezone.
The sensor and input_datetime seems right, but in the cards they show one hour apart. I guess it is because none is GMT, but the card reports GMT for the sensor.
In addition to that, but not related to the problem your are reporting now, I would suggest to change your input helper type from “Time” to “Date and time”, so you prevent another issue when displaying the cheapest time when it is after midnight.
In this case, go to Developer Tools, tab “Services” and then select YAML mode and paste this code over there, then press “Call service” and let me know if it runs properly (the button will be on green for a few seconds and your input helper should change) or of it fails (the button will be red for a few seconds and you should have an error message, which I’d like to know what is).
I saw the typo and corrected it before, but it didn’t work anyway. I did as you said and tried in Developer tools and it worked. Now it also works in the automation.
I have no idea why it didn’t work before, but thank you so much. I really appriciate it.
I actually have another question related to this. In the sensor I am using “now().hour” as start for the search. I would also like to use an input_datetime (configured as time) as end to make sure the car is charged before leaving for work. I have tried a lot of different things to convert the hours to an int, but cannot get it to work. As I understood it, strftime is the way to go, but it seems it is just fetching parts of the string, not converting.
Is there a easy way to make a sensor that says how many hours there is left to the cheapest hour? (ex. the cheapest hour among the next 6 hours)
It would be nice to have a screen next to the dishwasher that says how many hours you should delay the start to hit that cheapest hour.
I suggest you go with @TheFes’s cheapest hour macro that provides all this information. This post is lengthy and his macro is easier to implement and you can get this information out rather easily.