Hi, I am trying to show on HA the turn-on and turn-off hours of a light.
This time comes from node-red in json format, sent via mqtt. This is the output in node-red debug window:
info : msg.payload : Object
object
on: "Fri, 17 Aug 2018 18:48:31 GMT"
off: "Fri, 17 Aug 2018 21:43:39 GMT"
state: "off"
In HA I have created two mqtt sensors, where I extract the on and off times from the mqtt topic.
Here I see that the date and time is in GMT format, and I’d like to extract only the time and convert it to my timezone (GMT+2 in summer, GMT+1 in winter)
This is the off time as seen in HA:
Fri, 17 Aug 2018 21:43:39 GMT
I have tried several templates but I haven’t been able to do this conversion easily (taking into account the summer/winter time)
With this one I have been able to get the time and the timezone:
{% set strtext = states.sensor.timer1_off.state %}
{% set strtext2 = strtext.split(’ ‘)[4]+’ ‘+strtext.split(’ ')[5] %}
{{strtext}}
{{strtext2}}
Wich gives as result:
Fri, 17 Aug 2018 21:43:39 GMT
21:43:39 GMT
Using as_timestamp(), timestamp_local and others only returned empty strings or the same string
Holy cow, I can’t believe how much time I spent figuring this out! Every other post seems to indicate strptime simply discards the timezone information, but using “%z” and “+0000” works like a charm.