Weok
(Gerry)
April 25, 2019, 8:57pm
1
Howdy,
I’m trying to figure out a way to convert from UTC to CDT. Can anybody point me in the right direction?
This is the sensor I’m using to pull the data in, I just have no clue how to do the conversion.
sensor:
- platform: rest
resource: https://statsapi.web.nhl.com/api/v1/schedule?teamId=25
name: nhl_game_status
scan_interval:
hours: 24
value_template: '{{ value_json.dates[0].games[0].status.detailedState }}'
json_attributes:
- dates
- platform: template
sensors:
nhl_game_date:
friendly_name: "NHL Game Date"
icon_template: mdi:mdi:hockey-puck
value_template: '{{ states.sensor.nhl_game_status.attributes["dates"][0]["games"][0]["gameDate"] }}'
Currently it’s returning this info:
2019-04-26T01:30:00Z
Any help would be appreciated.
Assuming CDT is the local time of your HA machine, this or this link shows you how to convert UTC to your local time. The first link has a time in the format you’re receiving.
You should not need to convert it. It’s a utc time and as long as you have the right Timezone in HA it should deal with it and show correct local time with no conversion.
Weok
(Gerry)
April 26, 2019, 2:18am
4
I do have my timezone configured, but it’s not converting it. I’m pretty new to using the rest sensor, so I’m not sure if I’ve done something else wrong.
homeassistant:
elevation: !secret elevation
latitude: !secret latitude_home
longitude: !secret longitude_home
time_zone: !secret time_zone
What do you see if you set the device class to date time? (I think it’s datetime). My dates and times are showing correct in Lovelace.
Weok
(Gerry)
April 26, 2019, 2:42am
6
Looks like device_class is the answer. Thanks!
nhl_game_date:
device_class: timestamp
friendly_name: "NHL Game Date"
icon_template: mdi:mdi:hockey-puck
value_template: '{{ states.sensor.nhl_game_status.attributes["dates"][0]["games"][0]["gameDate"] }}'
Sweet! I had so much misery with dates and iOS but your datetime was in exactly the format you can do anything with.
1 Like