MQTT driven toggle, listen for actual toggle

So, I have a mqtt reciever for a physical on/off device, connected to a toggle/switch (on a dashboard) in node-red, which is connected to a mqtt transmitter.

What I want to achieve is that this same toggle should be triggering an OK/Cancel dialog. This is actually working, but I now realize that this dialog is (of course) prompted when the state of the thing is changed from somewhere else.

The full scenario is that it is a plug for a lamp. The lamp is connected with Homey (which is talking on the mqtt where i'm using node-red). On my Homey I have a flow that automatically triggers this lamp on/off. Activating this lamp manually with the node-red dashboard toggle should probably mean "pause the lamp flow until toggled again", why I want to prompt this dialog. :slight_smile:

I can of course have another switch controlling the flow next to the lamp toggle, but this switch may not tell the truth about the current state of the flow. Switching flows from active to inactive does not get on the mqtt. Therefore a prompt with "yes/no" feels most practical.

So, any suggestions for how to know if the switch was toggled by a human, or do you guys have any other smart solutions or thoughts?

(Yes, I'm quite sure I could toggle the switch programmatically by calling the Homey in any other way than mtqq, but i just got tired of this now and I'm hoping for an inspirational "hey, just solve it this easy" :slight_smile:)

You haven't shared the relevant part of your flow, so I am guessing a bit, but if you are using the dashboard switch node then change it to not pass messages through, and to Show state of input.

I'm not really sure what you mean. I still want it to pass a message to the light transmitter node. The problem is when something else toggles the switch. This makes the switch to change state, and that in it's turn triggers the confirm message on my dashboard.
Here's the flow, if I connect the "Switch VVB" to setup query, this query->confirm->switch->send is triggered every time something changes the state of the lamp.

Exactly what is the sequence that causes that? What happens at each node in your flow? I don't see the OK/Cancel node there.

Do you mean that you don't know what I mean by

Then look in the config for the ui_switch node and you will see those settings there.

I have marked the dialog node below.

Regarding the pass through, i tried to turn it off and it did exactly what I expected;

  1. I toggled the switch, the prompt came up and I could choose to have flows active or inactive.
  2. I then toggled the lamp back off in my homey. No confirmation message came up (good), but the state of the switch were still on/green.

I was thinking of a button and css hacking this button to stay on top of the switch, an then set it to transparent. When a user clicks this switch, they are acutally pressing the invisible button. This button takes the inverted switch state, sends to lamp (mqqt) and prompts about the floes questing. When mqtt message is send homey will turn the lamp on/off and send it's state to mqtt, and the dashboard will toggle the switch the user thought it pressed.

I am not however not a real fan of that kind of hack, it should be possible to solve more logical :slight_smile:

Have you set it to show the state of the Input?

Why put flow logic in 2 separate locations? I'd suggest consolidating your logic in Node-Red and limit Homey to just a hardware control layer and let Node-Red do what it was designed to do, run logic flow which would simplify the complexity.

Just my $.02

There are flows in different flow locations, yes, but they are spearated by design. All flows in node-red are dashboard related only. My plan is to have a wall mounted touch screen for overview (electricity usage, costs etc) in first place, and secondly some interactions with some things as well.
If the node-red is taken down, my lights and flows and everything is still working as normal. node-red in this case is just a client, and does not do anything more than in this case toggles some switches and is allowed to disable some related flows in homey.

That checkbox + select just solved the whole problem. You are now a legend in my eyes, thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.