Closed maiorfi closed 9 years ago
Hello, Vis in ioBroker environment asks at start the state of all variables. In node-red there is no such possibility and this should be solved by just cyclic sending of all variable values that used in widgets.
Regards, Bluefox
But may be it is good idea to hold values of all variables and give it back when view is opened.
Must think about it.
Let me tell you how I solved this: I noticed that vis is sending out three messages when the view is changed or reloaded. One of the messages has the topic "vis.control.command". I feed this topic as "page_reloaded" into an MQTT node. Let's say I want to turn a light on/off. This would be the flow: The inject node would be the normal way to turn your light on/off. The content of the function node is this:
context.light_State = context.light_State || null; //preserve state between invocations
if (msg.topic == "page_reload") {
// send last state again
msg.topic = "set if necessary";
msg.payload = context.light_State; //reload the last saved state
} else if (msg.topic == "light1") {
//do something to switch the light on/ff
context.light_State = "1"; // save the current state
}
return msg;
So if the message comes in from the MQTT node with the topic "page_reload" it just resends the payload with the previously stored state.
Hope this helps until we find something better. ;-)
Hermann
Ok so here are some restrictions to this method: The output of the three messages seems to be dependent of the OS and the browser type. Windows 7 PC Firefox - works ok. Messages sent out Chrome - works ok. Messages sent out
Android tablet Version 4.2.2 Firefox - works ok but no messages sent out. Chrome - shows only "No connection to server". It won't open node-red either...
Android phone Version 4.1.1 Firefox - works ok. No messages sent out Chrome - works ok. No messages sent out
Any idea why this happens?
Nice solution. Can I close the issue?
Hi. In your guide you say "The only issue is at start all drawn controls must receive the value."
What do you mean, exactly? If I open a view after a node-red flow containing corresponding vis node, how could I re-sync widget state? Is there a way vis can ask for initial state?
Thanks!