Input_datetime automation problem

I’ve been reading on automation’s and looking at example etc.
And I think my configuration should work but it does not, and I don’t understand why. Any help would be appreciated.

I want my MQTT light to turn on at the indicated time.

mqtt:
    broker: XXX
    username: XXX
    password: XXX


sensor:
   - platform: time_date
     display_options:
        - 'time'


light:
    - platform: mqtt
      name: "Bed Light"
      state_topic: bedroom/bedlight/state
      command_topic: bedroom/bedlight/command
      payload_on: "on"
      payload_off: "off"



input_datetime:
        bed_light:
                name: Start bedlight
                has_time: true



automation:
        - alias: control bed lights
          trigger:
                  platform: template
                  value_template: "{{ states('sensor.time') == (states.input_datetime.bed_light.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
          action:
                  - service: light.turn_on
                    data:
                        entity_id: light.bed_light

I would suggest playing around with the templates under the developer tools to check that your statements are actually what you think they are.

Put this into the templates tool, {{ states(‘sensor.time’) == (states.input_datetime.bed_light.attributes.timestamp | int | timestamp_custom(’%H:%M’, False)) }}

Interesting tool! Thanks for the tip.

Playing around there have me confident that the template is correct (It returns true when it should), thus the automation should trigger.

So now I’m really confused why the light does not turn on. (I can turn on it manually but not through the automation :confused: ).

Problem solved…
The code above worked correctly, the issue was that I had two “automation” keys in my configuration file. Putting the automation’s under the same key fixed the issue.

1 Like