Modbus: Button instead of Switch

I am connecting Home Assitant to my existing PLC using Modbus. I can sussefully configure a switch and connect it to a coil.

But now I have one coil (garage door) for which I do not want to toggle state (0/1) using a switch but just want to send a pulse to it using a button.

The goal: I have a button shown in Home Assistant. When I click on the button is sets the coil to “1” for a certain time period (e.g. 100ms) and then sets the coil back to “0”.

Can this be done in Home Assistant? Any pointers to where I can find documentation on how to do that?

Thanks a lot for any hints.

You can use a script, and it will appear as a button on the interface.
An alternative is using a switch, and an automation that sets it to off after it has been turned on for 100ms.

The script aproach sounds good. In such a script I would need a function to write a coil. I was searching the documentations but could not find out how to write such a coil from a script. Could anyone point me in the right direction how I can write a Modbus coil from a script? Thanks.


Has this been solved?

My 2 cents…I have done this with function into the PLC. I use the switch in Hass to “set” or “reset” coils. This is pure a PLC configuration and as such easier to solve than with a script.

Let me know if you need more information on the PLC programming. I can look it up if you want.



Good idea about doing this in the PLC! But I have solved it in a different way:

  • New coil in the PLC that has the status “door open” or “door closed”
  • Then a switch for this on HASS
  • When I set the switch to “off” (=door closed) the PLC ensures that the door is closed by issuing the according pulse commands to the door controller

So again: a pure PLC solution because I am too dumb to program HASS. :wink:

Hi there

I got also the Problem as I use a WAGO 750-841 for my whole house control… I use the Function “Stromstoss” on my Wago for all binary Lights and other stuff, as I use pushbuttons 24VDC to control evereything and know I would’nt programm any new PLC- Components on it for every application on my PLC…

@arnadan or @abmantis
you spoke of a script, where do I found information upon this?

Thank you very much


In HA configuration. Just create a script that calls the service you have.

thx, got it - found this

  - id: button1_auto
      platform: state
      entity_id: input_boolean.button1
      - service: switch.turn_on
          entity_id: switch.Switch1
      - delay:
          milliseconds: 300
      - service: switch.turn_off
          entity_id: switch.Switch1
      - service: input_boolean.turn_off
          entity_id: input_boolean.button1


Hello there…

sorry for using this old topic, but making a new one and clarifying, what i mean is surely not necessary.
I used this Code as described here to toggle a modbus coil (send a “1” to the WagoPLC - which itself in code resets this “1” in the register to “0”).

It works very well as described here, but i have several coils to use, so is there a possibility to parameterize an automation , so i only have to declare 20 buttons like:


and in the automation it reacts to all these buttons, but “reads” the buttons number (as a parametre maybe) and depending on this it switches different coils (Adresses) of the modbus / wago?
So that i can prevent too much automation scripts…

Its hard to describe if english isn’t your foreign language :wink:

BR Stephan

Nobody any idea?