nragon / keeper

A service to monitor and maintaining MQTT and HomeAssistant
MIT License
28 stars 6 forks source link

set timestamp format to be compatible with lovelace and device_class: timestamp #2

Open diplix opened 5 years ago

diplix commented 5 years ago

lovelace and the newish device_class: timestamp need a timestamp format like this: 2019-07-22T07:26:00+02:00

this could be accomplished by changing the TIME_FORMAT constant in constants.py: TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z"

however this produces an UTC timezone without colons (which HA needs): 2019-07-22T07:26:00+0200

i’m not very good at python, so i put this into constants.py

TIME_FORMAT = "%Y-%m-%dT%H:%M:%S"

and hard coded this into connector.py and heartbeater.py:

last_message_fmt = strftime(TIME_FORMAT)+"+02:00"

after that, this works:

  - platform: mqtt
    state_topic: "homeassistant/sensor/kpLastHeartbeat/state"
    name: kpLastHeartbeat
    icon: mdi:calendar-clock
    device_class: timestamp

may be you have a better idea how to do that with datetime.isoformat in python.