Using the push button: help!

Hello everyone,

I’m playing with the Push button feature of the MQTT integration.



From what I see and what I read from @pierre-gilles, as soon as you click it it sends 1 to MQTT, which I have:

I have a Zigbee plug that I turn on every day at 22:00 and that I stop at 06:00 via a scene.

My first problem is knowing the state of this push button (1 or 0), and I don’t know which MQTT functionality to use nor which topic to listen to.
I tested with a plug switch but it doesn’t do what I want at all.
Basically here’s an example of the result I’d like (active/inactive):

My second issue is using it in a scene.
When I click the push button to change its state, I want a scene to run to update my state feature (previous point) but the trigger doesn’t work at all:


From what I’ve investigated, the state change of my push button « retrieves » the values from the button click. However it should be 1 or 0 (or something else because I tested On and Off but the values are 7 and 8 so nothing to do with that).

If someone can help me, I’d be delighted :hugs:
Thanks in advance!

First, choosing a push button may not be the right choice if you really want it to return to 0 :smiley:

The principle of a push button is precisely to have only "1"s, never 0.

Otherwise it’s a binary « On/Off » device that you want, which will have a toggle like a connected plug, with 2 states « On » and « Off ».

I just tested, and it works fine for me :slight_smile:

I don’t know if you use messages in scenes to test a behavior, it’s handy!

I recommend using the « Send an MQTT message » block which allows you to record a new sensor value via the MQTT topic of a Gladys device.

For example, I have a device « Ouverture de porte », I copy its MQTT topic to publish:

And then I can publish to that topic any value, « 1 » or « 0 »:

Alors je ne veux pas de toggle, juste un push button pour « envoyer une impulsion ».

Je suis d’accord avec le 1 mais c’est moi qui le remets à 0 dans ma scène.

En fait un bouton poussoir (pour moi) envoie un 1 quand on appuie et ensuite devrait revenir à 0 (tout seul avec un timeout ou en mode manuel comme je veux le faire), ça agit comme une impulsion.
Si ton bouton poussoir à toujours un état à 1, comment savoir que tu l’as actionné ?

Ok donc je viens de tester avec un premier état à 0 et la scène fonctionne, et ensuite avec un état déjà à 1 et ça marche aussi … alors là je ne comprends pas le coup du changement d’état en passant de 1 à 1 :confused:, si tu peux m’éclairer @pierre-gilles car je sèche.

De mon côté je récupère la valeur du bouton poussoir. Ca fonctionne pour le message MQTT et avec Telegram :




C’est sur mon dashboard que ça ne veut pas faire ce qu’il faudrait : je devrais avoir Actif ou Inactif comme pour mes indicateurs d’état de lave-linge (même fonctionnalité : Commutateur) mais j’ai Aucune valeur reçue en rouge (quand c’est 0) et en vert (quand c’est 1).



Et je complique le truc un peu plus :

  • au bout de plusieurs secondes (temps non fixe) le rouge devient vert sans cliquer sur le bouton poussoir
  • je switche de dashboard, je reviens sur celui-là et là je vois Actif en vert pendant qq secondes puis Aucune valeur reçue en vert toujours :frowning:

Si tu as plus d’élément pour éclairer ma lanterne, je prends.
En tout cas merci pour tes premiers retours, ça me rassure déjà dans ce que j’avais mis en place et où je ne m’étais pas trompé.

Short video to illustrate the weird stuff:

Hi @mutmut :slight_smile:

It’s hard to help you without seeing the complete flow, in my opinion you’re making a mistake somewhere, in a scene, in Node-RED, or elsewhere.

I just ran a local test, a « Sensor switch » does have the expected « Active/Inactive » behavior:

My advice: review your scenes with a clear head, and add Telegram logs

Hi @pierre-gilles
regarding my scene, it’s only what I have above, that is a first block to get the push button state and then a second block to send an MQTT and Telegram message. And I have nothing else (no Node-RED nor other scenes) :confused:

And to test and set back to Inactive, I do exactly what you do in your video via MQTT Explorer (equivalent to MQTTX).

I added a graph to see what’s happening:


So you can see that I’m on On (the red is Off) but on the MQTT side I’m at 0 since yesterday:

and I didn’t press the push button yesterday:
![image|690x282](

Back with new tests on a new Gladys and MQTT instance: everything works as you show in your videos @pierre-gilles

So I created a second Switch feature with a different name and I deleted the other Switch, updated my scene and … it works correctly :thinking:

So the only thing I did was create a feature that takes the name of an existing feature and that overwrites the old one when saving (which I do quite often).
This time it messed things up and I think the problem came from that, but I can no longer say which feature was created first.

Thanks again for your help, I’m « resolving » this issue!

1 Like

Great, glad it’s working! :slight_smile:

And yes, be careful — it’s best to avoid reusing external ID names; it can cause problems.