Send the state of a switch every 5 seconds without changing the state of the switch

I have a switch that controls whether a window is open or not. The switch is only intended to be triggered in the UI. I also have a weather update. I want combine the switch state and the weather conditions every 5 seconds and then send it to my MQTT broker.

It works fine with the weather condition, but when I use an inject node to see what state the switch is in, it switches to off every time. How do I get the state of the switch without changing anything?

Here is the switch configuration:

Would it be feasible to store the state of the switch instead of interrogating the switch? If the switch changes state update the stored value?

Yeah that could work. As long as the switch only changes state when the UI is used and it sends data at a regular interval. I'm not sure how to do that though.

If you only want the switch to be changed via the UI then don't connect anything to its input.
You don't need the switch to send data regularly, just when it is changed changes.

I need the switch to send its state every 5 seconds. I need that information.

Why? The Join node will keep that latest value for you and pass it on when the http request sends a new value. If you have configured the Join node correctly.

How do I configure the node correctly?

I receive weather information every 5 seconds and I always want to send an array containing [window_state, weather_information].

Show us what the data coming from the function looks like and exactly what you want to send to mqtt.

However, this is one of the few cases where I think using a Flow variable might be easier, as suggested earlier in the thread. Feed the Switch into a Change node configured to set a flow context variable with the switch state, then pick that up in the function node and build the MQTT message in the function node.

Thank you for the help but this is too big of a hassle. I will live with only receiving a message when the switch is switched.

Or use a delay node instead of the inject node?

Feed the message from the switch node back to the switch, with a delay of 5 sec. So the switch gets triggered after 5 sec by itself and sends its state- as requested.

To let the switch not turn off itself, you have to feed it with true/false depending on his current state.
You defined the switch to send "window_open/window_close", so you need to change that back to "true/false" - via change nodes - before you feed it back to the switch.

If you just need to regularly repeat the previous message, then the Trigger node has an option to do that. Resend every ...

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