Adding multiple times to a trigger?

How do I set multiple times on a trigger? In my below config, the switch turns on at 23:00 with no issues. But it doesn’t turn on at 23:45. This would be if I turn the switch off at 23:10, it should turn on at 23:45.

automation:
  - alias: 'Sonoff auto-on at 11:00'
    trigger:
      - platform: time
        at: '23:00:00'
      - platform: time
        at: '23:45:00'
    action:
      service: switch.turn_on
      entity_id: switch.sonoff_switch

You botched the formatting, see the big blue box at the top for details. In short, you should have used the </> button to mark it as preformatted text.

If you can edit your post, or post it correctly formatted, somebody will be able to help.

How’s that?

Ok, that should work. I’ve not got any that use multiple time triggers, but I do have other multiple trigger automations that use time for one. Is there anything in the console log (how you find it depends on how you installed HA, and what OS you’re using) at 23:45?

It worked last night. I’ve noticed sometimes when I manually toggle an MQTT switch, HASS displays an error about connecting to the MQTT server. Then I have to toggle the switch again. Maybe that’s what happened when the trigger didn’t work. HASS should retry itself a few times before erroring out.

Where’s your MQTT server, local or remote?

It’s probably worth raising that as an issues.

It’s a local mosquitto server on the same raspberry pi.

Are you using 127.0.0.1 for the IP to connect to, or the LAN IP?

I’m using 127.0.0.1

That should be ok. Next thing to do is check to see if there’s anything in the Mosquitto logs to show the error.

Are you running on a Pi A, B1, B2, B3, or Zero?

It’s a pi3 running the all in one installer. I don’t see a mention of the error in the logs. If I can duplicate the error I’ll post more info.

If you get it to repeat, and you’ve got some log data, I’d raise an issue as I detailed above.

Ok, thanks for the help.

I am a bit unclear as to your actual intention with the script. Are you trying to provide a keep alive so that the switch maintains a certain state for a predefined period of time? or is there a metered rate, such as every 45 min, that you wish to check on the state and switch on or off??

Here is the way I interpret your question and another way of tackling this issue. The automation should check for a state change and perform an action if that state changes. If a switch gets turned off between a determined time frame, the switch will automatically be turned back on. This does have an instant effect while your solution has a timed lag. I do not know if this is desirable or not for you situation

Keep in mind that the below only checks state and performs an action. You would still need an automation to turn on the switch initially.

automation:
  - action:
    - data:
        entity_id: switch.your_switch
      service: switch.turn_on
    alias: Switch Keep Alive
    condition:
    - after: '22:00:00'
      before: '23:59:49'
      condition: time
    id: 'xxxxxxxxxxxxx'
    initial_state: true
    #hide from states panel as it only runs if the state changes during the predetermined times.
    hide_entity: true
    trigger:
    - entity_id: switch.your_switch
      from: 'ON'
      platform: state
      to: 'OFF'

I have a dehumidifier I sometimes shut off because it’s noisy. I want it to automatically turn back on at 11:00 when everyone goes to bed. Sometimes we’re up late though so I shut if off after 11:00. That’s why there’s a second trigger to turn it on at 11:45.

Hi there, did you get it to work, if so, how? Thank you.

Yes it works, you just list multiple triggers as you’d do for any other automation.