Solved - Help converting UTC to CDT

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.

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.

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