UTC to local time for a sensor to tts automation

I think you could use as_local to convert. Adding 3 hours is only a hack which will not survive the switch to or from DST. Templating - Home Assistant

      message: >-
        Good morning the value is {{ states('sensor.jewish_calendar_upcoming_candle_lighting') | as_timestamp | timestamp_custom('%H:%M') }}

won’t it need converting to localtime?

timestamp_custom converts a Unix timestamp to local time by default.

Filter timestamp_custom(format_string, local=True, default) converts an UNIX timestamp to its string representation based on a custom format, the use of a local timezone is default. If that fails, returns the default value, or if omitted the unprocessed input value. Supports the standard Python time formatting options.

1 Like

I knew you’d be able to correct me :slight_smile: Love your work!

1 Like

You were right about using as_local but it would be employed for converting a datetime object from UTC to local.

In the following screenshot, if I were to remove as_local the resulting time would be UTC as opposed to local (19:26 instead of 15:26).

1 Like

Thank you. So how would I need to update my script accordingly?

Per post 6

I replaced it with updating message but now it says the value is none even though the value is a specific date and time for the sensor result.

message: >-
        Good morning the value is {{
        states('sensor.jewish_calendar_upcoming_candle_lighting') | as_timestamp
        | timestamp_custom('%H:%M') }}

If it doesn’t have the date and time in a format understood by as_timestamp then it will fail to be converted to a timestamp.

Post an example of the sensor’s value.

2022-05-07T02:24:00+00:00

Above is value.

as_timestamp can easily convert that string to a timestamp.

Copy-paste this into the Template Editor:

Good morning the value is {{ states('sensor.jewish_calendar_upcoming_candle_lighting') | as_timestamp | timestamp_custom('%H:%M') }}

Let me know what it reports.

It reports same as what tts says:

Good morning the value is None

That’s the result you get if the sensor doesn’t exist or has a value that cannot be converted to a timestamp.

Ok so how to convert this result correctly since it includes both date and time can it just ignore the date and read the time and it so how?

Do the template in the developer tools bit by bit. Start with

{{ states('sensor.jewish_calendar_upcoming_candle_lighting') }}

Then try

{{ states('sensor.jewish_calendar_upcoming_candle_lighting') |as_timestamp}}

and so forth, until you can see what may be wrong.

They all return either unavailable or none.

Fix the sensor first then, what does dev tools|states say the state is?

Without any added states it returns:

2022-05-07T02:24:00+00:00

With the first added it shows unavailable with the second added it returns none.

I can’t work out what you mean by “added states”. The entity has a state. It is shown in the “States” tab in Developer Tools.