Receiving a time value via MQTT?

Hi there!

I want to automatize a turn on / off command based on time that I set in iobroker.
From there, I forward the time, e.g. “09:00:00” (without the ") via MQTT to Home Assistant. This arrives as a string.

When trying to set the device_class to “timestamp”, nothing gets received at all; when I remove the device_class, the string arrives in HA … but I cannot use this sensor for a time automation.

Does anyone have an idea how to solve? I also have the single components (hours, minutes, seconds) available via MQTT if needed.

Currently it looks like this (in my MQTT yaml)

  - name: Uhrzeit Sonos AMP ausschalten Wochenende
    state_topic: "ioBroker/Sound/Uhrzeit Sonos AMP ausschalten Wochenende"
    device_class: timestamp
    unique_id: Uhrzeit Sonos AMP ausschalten Wochenende

Many thanks for any guidance !
Steffen

The value of a Timestamp Sensor cannot simply contain the time, it must be date and time (and in ISO format).

If given a time, the today_at() function reports the current date and time in the appropriate format.

  - name: Uhrzeit Sonos AMP ausschalten Wochenende
    state_topic: "ioBroker/Sound/Uhrzeit Sonos AMP ausschalten Wochenende"
    value_template: "{{ today_at(value) }}"
    device_class: timestamp
    unique_id: Uhrzeit Sonos AMP ausschalten Wochenende
1 Like

Thank you very much! This helped :slight_smile:

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.