MQTT switch that is not a switch, but a command publisher. Not quite right

I have all of my ESPEasy units set up to look for an inbound command with a payload of 1. This will tell the units to push out their IP address so that I can always find them with ease.

As you can see I have a command for ON state with the payload of 1, this works fine from the front end. But, It is a switch, so it needs to be switched back to off to use it again. Short of defining on and off both with a payload of 1, is there a way to have a switch that always reverts to off or to have a push button that one can just click to send the command out to the units?

  - platform: mqtt
    name: "Query all"
    command_topic: "cmdMQTT"
    payload_on: "1"
    retain: "false"

Maybe instead of a switch you want a script that publishes an MQTT message. In the UI it will just show up as an “Activate” button.

Or indeed put a very small delay in the action of the script and it will show as a switch and turn back off after the delay (assuming the “switch” look is what the op is after)

Alternative with the way is is now is I believe setting a state_topic that always returns a zero will achieve the same.

As @exxamalte & @andrewdolphin mentioned, use a script instead :slight_smile:

trigger_ip_send:
  alias: Trigger IP Send
  sequence:
    - service: mqtt.publish
      data_template:
        topic: 'cmdMQTT'
        payload: '1'
    - delay: 00:00:02
    - service: mqtt.publish
      data_template:
        topic: 'cmdMQTT'
        payload: '0'

That makes so much sense! I have many automations and I really do not understand scripts yet. I will get there!

In the above example, what would get placed on the state card? There is not a switch or group or other entity?

Thanks for the point in the right direction!

Place the script itself on the card. The script is an entity in itself

I am a little dense… so this would go inside of my “group”? And then would display on the proper group tab in Hassio?

If the example above were used, I would put

script.trigger_ip_send

on the group card.

trigger_ip_send:
  alias: Trigger IP Send
  sequence:
    - service: mqtt.publish
      data_template:
        topic: 'cmdMQTT'
        payload: '1'
    - delay: 00:00:02
    - service: mqtt.publish
      data_template:
        topic: 'cmdMQTT'
        payload: '0'

This goes under script: and will create the entity script.trigger_ip_send that you can use to place inside any group: of your desire

Exactly that yes

This is awesome! Thanks guys, now I have my first of what I assume will be many scripts!

I had to move quote the alias entry to make it correct…

script:
  trigger_ip_send:
    alias: 'Trigger IP Send'
    sequence:
      - service: mqtt.publish
        data_template:
          topic: 'cmdMQTT'
          payload: '1'
      - delay: 00:00:02
      - service: mqtt.publish
        data_template:
          topic: 'cmdMQTT'
          payload: '0'

So, I added a second script to the above group and now there is a switch at the top by the name of the card. Can that switch be suppressed, so it is not seen or not usable?

That switch acivates all of the scripts on the page, really not wanted!

image

Add “control: hidden” when defining your group