How to prevent event reflection effects

Hi community,

i recently moved from my long-year openhab installation to home assistent, and i’m REALLY impressed. There are may of my devices supported natively; what i did not find (or like), i could integrate via some rest calls via NodeRed.

The problem i have now is somehow connected to the pattern i use. For example for OpenSprinkler:

I define several input booleans to represent the valves. When the turn true, i open the valve (for 10 MInutes).

In order to be able to stop any program that runs on OpenSprinkler, i poll as well every minute the status of the valves.

Looks like:

The Flow as JSON

This text will be hidden
[{“id”:“123aa3f5.2da0ac”,“type”:“tab”,“label”:“Wasser”,“disabled”:false,“info”:""},{“id”:“9f0dcb5d.e39348”,“type”:“server-state-changed”,“z”:“123aa3f5.2da0ac”,“name”:"",“server”:“1aed8413.1fd97c”,“version”:1,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:""},{“property”:“icon”,“value”:""}],“entityidfilter”:“input_boolean.vorgarten”,“entityidfiltertype”:“exact”,“outputinitially”:false,“state_type”:“str”,“haltifstate”:"",“halt_if_type”:“str”,“halt_if_compare”:“is”,“outputs”:1,“output_only_on_state_change”:true,“x”:200,“y”:160,“wires”:[[“c106b2f.fd7e85”]]},{“id”:“a26d1c24.7688c”,“type”:“server-state-changed”,“z”:“123aa3f5.2da0ac”,“name”:"",“server”:“1aed8413.1fd97c”,“version”:1,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:""},{“property”:“icon”,“value”:""}],“entityidfilter”:“input_boolean.sprinkler_beet”,“entityidfiltertype”:“exact”,“outputinitially”:false,“state_type”:“str”,“haltifstate”:"",“halt_if_type”:“str”,“halt_if_compare”:“is”,“outputs”:1,“output_only_on_state_change”:true,“x”:210,“y”:240,“wires”:[[“633e9163.9c15a”]]},{“id”:“3113eb5b.9f1a84”,“type”:“server-state-changed”,“z”:“123aa3f5.2da0ac”,“name”:"",“server”:“1aed8413.1fd97c”,“version”:1,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:""},{“property”:“icon”,“value”:""}],“entityidfilter”:“input_boolean.tropfschlauch_tomaten”,“entityidfiltertype”:“exact”,“outputinitially”:false,“state_type”:“str”,“haltifstate”:"",“halt_if_type”:“str”,“halt_if_compare”:“is”,“outputs”:1,“output_only_on_state_change”:true,“x”:240,“y”:200,“wires”:[[“79e8b719.1d1268”]]},{“id”:“18f3959.03fc76a”,“type”:“server-state-changed”,“z”:“123aa3f5.2da0ac”,“name”:"",“server”:“1aed8413.1fd97c”,“version”:1,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:""},{“property”:“icon”,“value”:""}],“entityidfilter”:“input_boolean.rasen”,“entityidfiltertype”:“exact”,“outputinitially”:false,“state_type”:“str”,“haltifstate”:"",“halt_if_type”:“str”,“halt_if_compare”:“is”,“outputs”:1,“output_only_on_state_change”:true,“x”:180,“y”:280,“wires”:[[“297ffbb1.e525b4”]]},{“id”:“b5a878b1.b36ca8”,“type”:“server-state-changed”,“z”:“123aa3f5.2da0ac”,“name”:"",“server”:“1aed8413.1fd97c”,“version”:1,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:""},{“property”:“icon”,“value”:""}],“entityidfilter”:“input_boolean.wasserhahn”,“entityidfiltertype”:“exact”,“outputinitially”:false,“state_type”:“str”,“haltifstate”:"",“halt_if_type”:“str”,“halt_if_compare”:“is”,“outputs”:1,“output_only_on_state_change”:true,“x”:200,“y”:320,“wires”:[[“4d9ff610.6fd3e8”]]},{“id”:“c106b2f.fd7e85”,“type”:“change”,“z”:“123aa3f5.2da0ac”,“name”:“station = 0”,“rules”:[{“t”:“set”,“p”:“station”,“pt”:“msg”,“to”:“0”,“tot”:“str”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:590,“y”:160,“wires”:[[“1fd54764.52e489”]]},{“id”:“79e8b719.1d1268”,“type”:“change”,“z”:“123aa3f5.2da0ac”,“name”:“station = 1”,“rules”:[{“t”:“set”,“p”:“station”,“pt”:“msg”,“to”:“1”,“tot”:“str”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:590,“y”:200,“wires”:[[“1fd54764.52e489”]]},{“id”:“633e9163.9c15a”,“type”:“change”,“z”:“123aa3f5.2da0ac”,“name”:“station = 2”,“rules”:[{“t”:“set”,“p”:“station”,“pt”:“msg”,“to”:“2”,“tot”:“str”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:590,“y”:240,“wires”:[[“1fd54764.52e489”]]},{“id”:“297ffbb1.e525b4”,“type”:“change”,“z”:“123aa3f5.2da0ac”,“name”:“station = 3”,“rules”:[{“t”:“set”,“p”:“station”,“pt”:“msg”,“to”:“3”,“tot”:“str”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:590,“y”:280,“wires”:[[“1fd54764.52e489”]]},{“id”:“4d9ff610.6fd3e8”,“type”:“change”,“z”:“123aa3f5.2da0ac”,“name”:“station = 4”,“rules”:[{“t”:“set”,“p”:“station”,“pt”:“msg”,“to”:“4”,“tot”:“str”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:590,“y”:320,“wires”:[[“1fd54764.52e489”]]},{“id”:“1fd54764.52e489”,“type”:“switch”,“z”:“123aa3f5.2da0ac”,“name”:“on or off”,“property”:“payload”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“on”,“vt”:“str”},{“t”:“eq”,“v”:“off”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:2,“x”:830,“y”:240,“wires”:[[“39138965.a43b86”],[“e0ebd311.d6ee2”]]},{“id”:“39138965.a43b86”,“type”:“change”,“z”:“123aa3f5.2da0ac”,“name”:"“http://192.168.178.112/cm?sid=” & msg.station &"&en=1&t=600"",“rules”:[{“t”:“set”,“p”:“url”,“pt”:“msg”,“to”:"“http://192.168.178.112/cm?sid=” & msg.station &"&en=1&t=600"",“tot”:“jsonata”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:1170,“y”:220,“wires”:[[“78dd616.d2f9ba”]]},{“id”:“e0ebd311.d6ee2”,“type”:“change”,“z”:“123aa3f5.2da0ac”,“name”:"“http://192.168.178.112/cm?sid=” & msg.station &"&en=0"",“rules”:[{“t”:“set”,“p”:“url”,“pt”:“msg”,“to”:"“http://192.168.178.112/cm?sid=” & msg.station &"&en=0"",“tot”:“jsonata”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:1150,“y”:260,“wires”:[[“78dd616.d2f9ba”]]},{“id”:“78dd616.d2f9ba”,“type”:“http request”,“z”:“123aa3f5.2da0ac”,“name”:"",“method”:“GET”,“ret”:“txt”,“paytoqs”:false,“url”:"",“tls”:"",“persist”:false,“proxy”:"",“authType”:"",“x”:1550,“y”:240,“wires”:[[]]},{“id”:“9477e294.9d746”,“type”:“http request”,“z”:“123aa3f5.2da0ac”,“name”:“http://192.168.178.112/jc",“method”:“GET”,“ret”:“obj”,“paytoqs”:false,“url”:“http://192.168.178.112/jc”,“tls”:"",“persist”:false,“proxy”:"",“authType”:"",“x”:350,“y”:560,“wires”:[[“1c21bff8.71c39”]]},{“id”:“1c21bff8.71c39”,“type”:“change”,“z”:“123aa3f5.2da0ac”,“name”:"",“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“payload.sbits[0]”,“tot”:“jsonata”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:600,“y”:560,“wires”:[[“858a8793.6e0358”]]},{“id”:“858a8793.6e0358”,“type”:“function”,“z”:“123aa3f5.2da0ac”,“name”:“BitArray”,“func”:"msg.payload=msg.payload.toString(2).padEnd(8,‘0’).split(’’).reverse();\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:820,“y”:560,“wires”:[[“e1d07526.e67818”,“a0e89442.c727a8”,“7801e00e.59abd”,“48f492c9.bd002c”,“3507e84b.31ff78”]]},{“id”:“e1d07526.e67818”,“type”:“switch”,“z”:“123aa3f5.2da0ac”,“name”:“0”,“property”:“payload[0]”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“0”,“vt”:“str”},{“t”:“eq”,“v”:“1”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:2,“x”:1050,“y”:400,“wires”:[[“48b0f40.7755d0c”],[“cce0636d.5cb81”]]},{“id”:“a0e89442.c727a8”,“type”:“switch”,“z”:“123aa3f5.2da0ac”,“name”:“1”,“property”:“payload[1]”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“0”,“vt”:“str”},{“t”:“eq”,“v”:“1”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:2,“x”:1050,“y”:480,“wires”:[[“e70e67a5.c40d78”],[“46d3904a.52b13”]]},{“id”:“7801e00e.59abd”,“type”:“switch”,“z”:“123aa3f5.2da0ac”,“name”:“2”,“property”:“payload[2]”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“0”,“vt”:“str”},{“t”:“eq”,“v”:“1”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:2,“x”:1050,“y”:560,“wires”:[[“1b790c29.dd1434”],[“e80b2a93.c51028”]]},{“id”:“48f492c9.bd002c”,“type”:“switch”,“z”:“123aa3f5.2da0ac”,“name”:“3”,“property”:“payload[3]”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“0”,“vt”:“str”},{“t”:“eq”,“v”:“1”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:2,“x”:1050,“y”:640,“wires”:[[“4da9c9ed.f02fd8”],[“a04e74a6.d808c8”]]},{“id”:“3507e84b.31ff78”,“type”:“switch”,“z”:“123aa3f5.2da0ac”,“name”:“4”,“property”:“payload[4]”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“0”,“vt”:“str”},{“t”:“eq”,“v”:“1”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:2,“x”:1050,“y”:720,“wires”:[[“b589b3c5.d3a39”],[“66e41f16.a0c55”]]},{“id”:“cce0636d.5cb81”,“type”:“api-call-service”,“z”:“123aa3f5.2da0ac”,“name”:“TurnOn”,“server”:“1aed8413.1fd97c”,“version”:1,“debugenabled”:false,“service_domain”:“input_boolean”,“service”:“turn_on”,“entityId”:“input_boolean.vorgarten”,“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1220,“y”:420,“wires”:[[]]},{“id”:“48b0f40.7755d0c”,“type”:“api-call-service”,“z”:“123aa3f5.2da0ac”,“name”:“TurnOff”,“server”:“1aed8413.1fd97c”,“version”:1,“debugenabled”:false,“service_domain”:“input_boolean”,“service”:“turn_off”,“entityId”:“input_boolean.vorgarten”,“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1220,“y”:380,“wires”:[[]]},{“id”:“46d3904a.52b13”,“type”:“api-call-service”,“z”:“123aa3f5.2da0ac”,“name”:“TurnOn”,“server”:“1aed8413.1fd97c”,“version”:1,“debugenabled”:false,“service_domain”:“input_boolean”,“service”:“turn_on”,“entityId”:“input_boolean.tropfschlauch_tomaten”,“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1220,“y”:500,“wires”:[[]]},{“id”:“e70e67a5.c40d78”,“type”:“api-call-service”,“z”:“123aa3f5.2da0ac”,“name”:“TurnOff”,“server”:“1aed8413.1fd97c”,“version”:1,“debugenabled”:false,“service_domain”:“input_boolean”,“service”:“turn_off”,“entityId”:“input_boolean.tropfschlauch_tomaten”,“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1220,“y”:460,“wires”:[[]]},{“id”:“e80b2a93.c51028”,“type”:“api-call-service”,“z”:“123aa3f5.2da0ac”,“name”:“TurnOn”,“server”:“1aed8413.1fd97c”,“version”:1,“debugenabled”:false,“service_domain”:“input_boolean”,“service”:“turn_on”,“entityId”:“input_boolean.sprinkler_beet”,“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1220,“y”:580,“wires”:[[]]},{“id”:“1b790c29.dd1434”,“type”:“api-call-service”,“z”:“123aa3f5.2da0ac”,“name”:“TurnOff”,“server”:“1aed8413.1fd97c”,“version”:1,“debugenabled”:false,“service_domain”:“input_boolean”,“service”:“turn_off”,“entityId”:“input_boolean.sprinkler_beet”,“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1220,“y”:540,“wires”:[[]]},{“id”:“a04e74a6.d808c8”,“type”:“api-call-service”,“z”:“123aa3f5.2da0ac”,“name”:“TurnOn”,“server”:“1aed8413.1fd97c”,“version”:1,“debugenabled”:false,“service_domain”:“input_boolean”,“service”:“turn_on”,“entityId”:“input_boolean.rasen”,“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1220,“y”:660,“wires”:[[]]},{“id”:“4da9c9ed.f02fd8”,“type”:“api-call-service”,“z”:“123aa3f5.2da0ac”,“name”:“TurnOff”,“server”:“1aed8413.1fd97c”,“version”:1,“debugenabled”:false,“service_domain”:“input_boolean”,“service”:“turn_off”,“entityId”:“input_boolean.rasen”,“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1220,“y”:620,“wires”:[[]]},{“id”:“66e41f16.a0c55”,“type”:“api-call-service”,“z”:“123aa3f5.2da0ac”,“name”:“TurnOn”,“server”:“1aed8413.1fd97c”,“version”:1,“debugenabled”:false,“service_domain”:“input_boolean”,“service”:“turn_on”,“entityId”:“input_boolean.wasserhahn”,“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1220,“y”:740,“wires”:[[]]},{“id”:“b589b3c5.d3a39”,“type”:“api-call-service”,“z”:“123aa3f5.2da0ac”,“name”:“TurnOff “,“server”:“1aed8413.1fd97c”,“version”:1,“debugenabled”:false,“service_domain”:“input_boolean”,“service”:“turn_off”,“entityId”:“input_boolean.wasserhahn”,“data”:””,“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1220,“y”:700,“wires”:[[]]},{“id”:“c786eb1c.9b0708”,“type”:“inject”,“z”:“123aa3f5.2da0ac”,“name”:“Every Minute”,“topic”:"",“payload”:"",“payloadType”:“date”,“repeat”:“60”,“crontab”:"",“once”:false,“onceDelay”:0.1,“x”:140,“y”:560,“wires”:[[“9477e294.9d746”]]},{“id”:“1aed8413.1fd97c”,“type”:“server”,“z”:"",“name”:“Home Assistant”,“addon”:true}]

The Problem now:

  • I start a longer Job on OpenSprinkler UI, like to refill out pond for an hour.
  • The status “on” is polled, and set to the input boolean (Great)
  • I get the status “on” back on the node red, and start to open the valve for 10 MInutes. (not Great)

So, i get my very own status change reflected back.

Technically i have the same issue with othe rintegrations, but there it has no negative side effect.

The best concept i could imagine now, is to tract the state of the valves somehow in NodeRed globals, with a timestamp or so, but thats feels odd. dddddd.

Is there a smart/commen way to tackle such issues?

Thanks for any hint,
Michael
PS: yes, i found the community integration for OpenSprinkler, but I’am more interested in the logical issue here…

A few thoughts…
It seems to me you are mixing two things. In the first section of your flow you are using your input_boolean as a trigger, while in the second section you are using it as a state. So I’d, probably create two sets of IB’s, to represent both items (state and trigger). I’ve not used it, but alternatively there is a custom node type you can install that creates dynamic HA entities for Node Red that you can control instead of having to pre-create input entities.

Then for an on trigger, check if the state entity is already on, and do nothing, or do something if it is off. Then do vice versa for off. Also you can set the state entity correctly.

Then for polling, set the state entity correctly and then wait a couple of seconds (because if you do it too quick you will have a race condition), set the trigger entity correctly.

I wouldn’t track state in global, because depending how you are setup, I suspect your nice red globals probably aren’t persistent, whilst HA entities are (if you don’t set a default value).

However you could do away with two entities, by storing date time on your polling flow, and checking in your trigger flow if it has been set in the last x seconds.

I’ve not tried to do this at this level because all my IoT entities come through integrations. I’ve taken on SkyQ, which is a challenge, but state is then hard separated from anything I might want to do to it.

Just read the other thread. You could achieve this via a restful sensor by the look of it to get the current state, then on change of state set the trigger input Boolean appropriately, with no race condition

Then in trigger flow, check current state as I suggested before.

I’m sure you could the represent this however you like in lovelace, but I think most people are saying you need state and trigger.

So I would need a Template swittch on top, which separates me state and command. Makes sense. Thanks!

Is there actually a way to trigger a flow from HA?

Just put the input boolean on any type of Lovelace card you like. You can toggle it and it will run the flow.

:slight_smile: Yes. But it turns as well, if i swicht it from node red

Sorry, not sure what you mean.

Well, i wiuld need to use a template switch to seperate state and event. With an Input boolean for the state.

korrekt?

if i would use the input boolean directly, what i do today, i have exactly the issue from my first post: If i change it from NR, i get the change event directly back to NR…

That reflextion i would want to break. My thought is, i could need an event raised by that template…

No point having a template switch that uses input boolean as it’s value, they are just one and the same thing then. You need two separately adjustable items.

You then need to check the state entity before auctioning a flow triggered by the trigger entity.

I thought on a template switch i could trigger a custom event…
That should actually only be triggered, if the button is pressed, not if the connected state sensor is changed. Somehting like:

sensor:
  - platform: template
    sensors:
      schlafzimmer_links:

cover:
  - platform: template
    covers:
      schlafzimmer_links:
        friendly_name: "Schlafzimmer Links"
        device_class: shade
        position_template: "{{ states('input_number.schlafzimmer_links') }}"
        open_cover:
          event: event_light_state_changed
            event_data:
              state: 0 
        close_cover:
          event: event_light_state_changed
            event_data:
              state: 100 
        set_cover_position:
          event: event_light_state_changed
            event_data:
              state: {{ covers.schlafzimmer_links.position }} 

usinf a sensor instead of a input bool. However, the config above does not work, and i gave up on it, with an attitude of beeing $%&/( about this YAMML hell.

My current approch is simply: If a Button trigger event comes, check first if it actually changes the target device.

This makes me another rest call and a bit bigger delay, but should be bullet proove i guess…

To be honest I can’t answer that. I do my automation in Node Red rather than trying to design stuff in YAML. Sorry.