Adding 2h to a incorrect timestamp

Hi Guys,
I am using the Gardena integration for my mower. When I get the “next start state” I am getting the wrong time, off by 2h. I’ve looked at the .py files with now obvious reason to why it’s that way. sensor.time is showing the correct system time.

I’ve tried to extract the time using from the timestamp “2020-05-14T17:45Z” with:

{{ (states.vacuum.blixten.attributes.timestamp_next_start.split("T")[1][:-1])}}

Which always gives me the next starting time (17:45) with two hours off. Time should be 19:45. The mower has the correct time both in the machine and in the Gardena app.

How can I add two hours to the timestamp using templating? Every attempt I done results in either the template not running in the developer tool or some other issue. For example (and keep in mind I almost don’t know what I am doing):

{{ (((as_timestamp(states.vacuum.blixten.attributes.timestamp_next_start)) | timestamp_custom('%H:%M', false))) + ((2)|timestamp_custom('%H:%M', false)) }}

Any ideas on how to get this working?

I also used regex to extract the time which works fine in the developer tool but not in my config file:

{{ strptime(state_attr('vacuum.blixten', 'timestamp_next_start') | regex_findall_index('\d{4}-\d{2}-\d{2}T(\d{2}:\d{2})'), '%H:%M:')}}

I’m assuming your local time zone is UTC + 2 hours. Is that correct? If so, then the time you’re getting is right, it’s just being expressed in UTC. To show it in your local time zone, the second parameter to timestamp_custom should be true, not false (or just leave it out.) So try one of these:

{{ state_attr('vacuum.blixten', 'timestamp_next_start')|as_timestamp|timestamp_local }}
{{ state_attr('vacuum.blixten', 'timestamp_next_start')|as_timestamp|timestamp_custom('%H:%M') }}
1 Like

You Sir, are my hero.

Thanks a lot!!!

1 Like

Hi @pnbruckner
Thanks again for your solution yesterday. I tried it out in the developer tool. I’ve added it som my config.yaml and am getting this error. Could you offer some advice on how to deal with that?

Config.yaml:

      blixten_nextstart:
        friendly_name: "Blixten nästa start"
        value_template: '{{ state_attr('vacuum.blixten', 'timestamp_next_start')|as_timestamp|timestamp_custom('%H:%M') }}'

Log:

2020-05-15 08:11:30 ERROR (SyncWorker_0) [homeassistant.util.yaml.loader] while parsing a block mapping
  in "/config/configuration.yaml", line 472, column 9
expected <block end>, but found '<scalar>'
  in "/config/configuration.yaml", line 474, column 41
2020-05-15 08:11:30 ERROR (MainThread) [homeassistant.bootstrap] Failed to parse configuration.yaml: while parsing a block mapping
  in "/config/configuration.yaml", line 472, column 9
expected <block end>, but found '<scalar>'
  in "/config/configuration.yaml", line 474, column 41. Activating safe mode

Thanks!
Rob

Worked it out.

Wrapping it in quotes fixed it:

Not:

'{{ state_attr('vacuum.blixten', 'timestamp_next_start')|as_timestamp|timestamp_custom('%H:%M') }}'

Instead use:

"{{ state_attr('vacuum.blixten', 'timestamp_next_start')|as_timestamp|timestamp_custom('%H:%M') }}"
1 Like