Delay fails in automation when triggered by switch


I have this automation which charges my bike battery. When i click the ON switch it’s supposed to count down and after 45 mins the plug turns on. But if i click the ON button on the switch, the plug turns on immediately. If i run the automation manually from the automations tab, the delay works, and the plug turns on after 45 mins as it should.
Any ideas?

alias: Start opladning af batteri (cykel)
description: ""
  - platform: time
    at: "23:15:00"
  - platform: device
    domain: mqtt
    device_id: 57959cab4502867b8e6413d791a26675
    type: action
    subtype: on-press
    discovery_id: 0x00178801086c96d7 action_on-press
condition: []
  - delay:
      hours: 0
      minutes: 45
      seconds: 0
      milliseconds: 0
  - type: turn_on
    device_id: ad36a03e883a12d26f582b90b2206ee4
    entity_id: switch.bryggers_plug_01
    domain: switch
mode: single


Hi, I think that there may be problem with the syntax of your MQTT trigger, the reason the automation works when you run the actions manually is because you are bypassing the triggers.

Try replacing the dashes ("-") in subtype and discovery_id with underscores ("_") to see if that helps.

If i do that i just get “unknown trigger”
Its just picked from the list in the GUI.

Is this a bug?

I don’t really know but I do think the problem appears to be with the trigger not working.

Are there any other options to pick from in the GUI that might work?

Failing that you could use MQTT Explorer to look at look at the message that is sent when you press the button.

Hopefully others may be able to offer some other suggestions.

Switch or button?

Does the light turn on if the automation is disabled?

An automation will not override the native/“hard wired” action of a switch. The exception would be if the switch supports a disconnected mode.

Same goes for a button bound to a light.

No it does not turn anything on if the automation is disabled.

I didn’t change anything. I just restartet home assistant, and the problem went away.
Did not know that was a thing.