I have “created” (more or less copy/paste from another HA user) a timestamp sensor that locates the cheapest continues hours to charge my EV car and it returns the start-time. It returns “17 februari 2023 kl. 22:00”.
I now want to move the time in format HH:MM to a helper (input_datetime.customvirtual_ev_starttid_for_smartladdning) to use in automations. I have put the following service call action in an automation to handle this specific function, but it doesn’t work. I have googled the issue and it seems to work for others.
Copy the following template into the Template Editor. You’ll see that as_timestamp is unable to convert the supplied datetime string into a timestamp value.
Correct, because in Home Assistant, python defaults to English (strptime is a python string method). As a result, it makes it more challenging to convert non-English datetime strings into a datetime object.
This is Developer Tools > Templates…
Probably will be easier to visualise if you share Developer Tools > States (filtering to that sensor you created).
But I can already see you have the right format (or almost)
So, now I could test your sensor and can confirm it return a valid timestamp, so you can use it as it is in your automation, without the need to store in a input helper, or you can still save to your input helper, but in this case you don’t have to do any transformation.
But again, you are using an automation to take a value from a sensor, transfer that value to an input helper without any transformation, so you will use the input helper as an input in another automation, right? Why don’t you simplify this by just using your original sensor (sensor.sensor_ev_cheapest_hours_start) in the final automation, with no need for a helper?
Take a look at this example using sensor on the documentation. It requires the sensor to have state_class: timestamp, which is your case:
Based on the investigation performed by EdwardTFN, it appears you don’t need a workaround. You have a Template Sensor configured as a timestamp sensor. You should be able to use it directly in a Time Trigger (see EdwardTFN’s example).
For future reference, when you tell people the value of an entity, report the value you see in Developer Tools > States. That’s the entity’s actual state value. What you see displayed elsewhere in the UI might be reformatted (in your native language or for cosmetic purposes).