Hi all
I am almost there but not fully; I try to make a switch in Node-Red to use in HA to control my house
s existing system.
My current system works like this:
Requesting device data is done by url http:// address/xyz/devicedata #which gives status info of all my controllable devices( in total 250 entities that I have to transfer separately to HA)
Request measurements and other info is done equally
Sending state change request is done with url
http://address/xyz/devices?opmode=setpin&uid=1771159508035&mask=128&values=128
and those values are different for each device in my system( the long string is the number of the control unit controlling relay outputs for 24 devices per module, the mask and value is different for all devices in a module).
Now, I am able to create a status element to HA from my server( measurement data entities were easy to create and device status equally) but I have to poll the info from the server with multiple url’s and that will overflow the server as it can handle only few requests simultaneously. Thus I collect a major list and extract the info to each element/ entity separately.
I am able to make a switch, which changes the state from on to off and vice versa. I am even able to have that switch in HA but that switch doesn poll my house system’s status. So, if I change the lights on, by said switch the house knows them to be on and HA knows them to be on and same with off via HA. But, if I turn the wall switch( a button), then HA doesn’t have the right status shown on the switch but I have to change the status twice to be certain the status shown by the switch is correct.
That said, how can I make a switch in Node-Red that it extracts the status data from my existing system every other second( timestamp is set to either second or two) but also acts as a switch?.
My current code looks like this:
It’s overcomplicated but essentially does what I want the switch to do:
- Device values are polled every second and formatted as XML and function 11 formulates mayloads of the read data in format msg.device_tvroom_rooflamp_state = msg.payload.response.unit[0]…$.value. Function 12 extracts only the value of tvroom_rooflamp
- switch creates an entuity called tvroom_rooflamp
- in case of value being 1, a http://address/xyz/device?opmode=setpin-for-on is sent
and for value being 0 another url is sent.
All debugs give the right outcomes even if I switch the light on from my exisiting system or HA but the swithc status doesn’t update.
Should I do separate entities of the status and the switch or is there means to combine these?
On an another note, is there means to have enities created from the phase 1) polling directly with one node ( as I already have 250 data payloads made on function 11 -node) or is the only way to create them to create them separately( as I have done for 90 measurement data entities already)