Dashboard Switch Trigger Msg on Deploy

Is there anyway to get the Dashboard Switch to send its msg when the node red flows are deployed?

I have a switch which sends a Mode msg (i.e. msg.payload=away) When the flows are deployed, the state of the switch is persistant, but it doesn't send its msg.payload so the downstream nodes don't know the mode context.

I tried using an inject after 1 sec into the switch, but that sets the switch to the inject msg. I tried sending the msg to a function that uses Context to track the switch state, but the Context is persistant. I see there is now a Persistant Context feature, but I haven't figure-out how to enable local file storage yet. Before I go through that, is there some other / simpler what of accomplishing what I'am after?

The dashboard is a visualisation of the backend state so yes you need to send it from the back end. A long way of saying no, you are on the right path with context.

I use MQTT retained topics to maintain persistent state such as switch positions. Send the switch output to a retained topic in MQTT and wherever that state is needed you can subscribe to the topic and receive messages whenever the switch changes. In particular configure an MQTT In node to subscribe to the switch's topic and feed that in the front end of the switch. Then whenever node red is restarted or that part of the flow is redeployed the switch will automatically get initialised to the retained state.
It has the additional benefit that you can organise the flow tabs so all the UI is on tabs reserved for UI and the logic associated with what to do when the switch or other UI status is changed is handled on flow tabs managing the system logic.

1 Like