Function to check input and output

Hello guys,

I'm using mqtt to send data to arduino. I use ui_switch to set my device on and off, and after arduino received my message, it send another message to confirm. With this message I set the ui switch to on and off (depending on input). So if arduino doesnt receive the message, the switch doesnt change state.

But since I use retain on the mqtt, arduino will recive the message as soon as it's online again. And I need this for automatic control and wifi connection issues.

I would like to show a notication when I use manual mode. If I press ui_switch and dont get response from arduino for 2 sec, I want to show this notification.

How I can implement this one with function node?

I dont know how to trigger the function node, because when arduino doesnt receive messege, it doestn send anything, so the function node is not triggered.

Why is that a problem? If you set the switch to not pass the message through, and to show the state of the output input then you can connect the switch to MQTT out and the MQTT In to the input of the switch an all should be well. When you click the switch it will send the message but not change state visually until the confirmation is received from MQTT.

Edited to correct typo.

If I change swith to show message of the output the switch state change. I dont want the state to change until something is really happens So I wait till I receive message from the mc.

Or did you mean I have to use input of the switch to show the state. Then yes, it works as you said. The switch only turns to on when the message from mc is recieved. But sometimes when you hit switch and nothing happens, cause arduino is offline, the value was send is still saved, thanks to retain. And when arduino comes online again, it will get the message and then change the state of teh switch. But you need to remember to put it off again. So when I hit switch and nothing happens, I just leave it as it is and forget about it. Thats why i need to show message, to turn the switch off again.

Ok I dont forget about it, but I cannot guarantee for my wife ;D

Sorry, I meant show the state of the input. I have corrected the post above.

I now understand the point about when the device is offline. Is that really an issue for you? My devices are offline only if there is a fault so it isn't an issue. I think you could do something clever with a trigger node to change the mqtt value back again after a few seconds if the confirmation is not received from the device. I have to go now though so I can't work it out immediately.

Yes I just rember that trigger node, after I did reply to you. And it works how I was expecting it. I set the trigger with the switch and if I receive mqtt message back, I reset the trigger. And I also set the retained message to 0, so I can avoid to start something when I dont expect it and still use retained messages

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