Working with conditions

Hello all node-red fans!

I'm working with conditions and tryng to match several ones to have a final result and make an action to happens. So...

I have this nodes so far.

The path goes like this:

  • check if im stay at home or away
  • check if lights are on
  • In the switch node i check that previous conditions

All things seems to be easy but the issue comes when i'm home and i turn on the lights the "out home" node starts and turn off the light.

There is something wrong about the condition check and how that is managed in node-red. Obviously im doing something wrong...

Any clue or help?

Regards!

Not at my computer but I suggest you put a separate debug node on the output of every node in the flow so you can see what is going on. And remember the old saying “computers tend to do what you tell them to do which isn’t always what you want them to do” :smile:

Not sure as we can not see the switch node settings,
The switch node checks all the conditions in order, it will check all unless it is set to stop after finding the first true condition.

Ok.
The switch node has this configuration.

The first condition checks whether im home or not. The weird thing is that i change this for example from home (being home) to not_home all works as equal as it is. I dont understand that part because it has to stop all the following process.

Maybe im misunderstanding something here.

Regards!

It is set to check all rules so, if you only want it to fire one rule if true, then change the checking all rules option.
As you have it set, if not_home is true that path fires. but then it Checks other rules.

Ok...so let me see if i get it.

The logical works weird because i know that all conditions need to be meet in orden to follow with the next node.

Here are the nodes so you can check it out.

[{"id":"371b5d1c.9c46c2","type":"tab","label":"Presence actions","disabled":false,"info":""},{"id":"b78fb400.7d8bc8","type":"comment","z":"371b5d1c.9c46c2","name":"todo ","info":"Hacer un schedule para vacaciones y que la luz\nse prenda automatica y se apague sola en bandas\nde tiempo, que me mande un mensaje tambien con esto.\nHay un nodo que hace esto, ver cron-plus nodo.\n\nhacer que se detecte la zona de casa, eso me \npermite ejecutar cosas en el rango de casa. \nSi es de noche y estoy fuera de la zona de casa\nno voy a querer que se prendan las luces. De lo \ncontrario si. Hay que ver como se hace con life360\nya que ahi se delimitan las zonas.\n\nEnviar un mensaje a telegram cuando llegue a casa y\ncuando salga de casa\n\na futuro....hay que instalar life 360 en el\ndispositivo de jime porque la politica\nde que realmente no hay nadie en casa y que dejamos\nuna luz prendida no seria posible.\nSi solamente me detecta mi dispositivo y me voy\nlos dejo sin luz a los que estan adentro.\n","x":150,"y":40,"wires":[]},{"id":"1b589a17.437956","type":"comment","z":"371b5d1c.9c46c2","name":"Apaga todas las luces cuando estoy en casa","info":"","x":210,"y":100,"wires":[]},{"id":"67dbe26f.4e82cc","type":"function","z":"371b5d1c.9c46c2","name":"enter home","func":"msg.payload = {}\nmsg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'TAB PRESENCE ACTIONS AVISO: Estas dentro de casa.';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":690,"y":240,"wires":[[]]},{"id":"505ae856.192da8","type":"trigger-state","z":"371b5d1c.9c46c2","name":"","server":"59ced628.1507a8","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"device_tracker.life360_martin_coria","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"not_home","propertyValue":"new_state.state"}],"outputs":3,"customoutputs":[{"messageType":"default","messageValue":"home","messageValueType":"str","comparatorPropertyType":"current_state","comparatorType":"is","comparatorValue":"home","comparatorValueDataType":"str","comparatorPropertyValue":"new_state.state"}],"outputinitially":true,"state_type":"str","x":220,"y":280,"wires":[[],["97e430b6.11b36"],["67dbe26f.4e82cc"]]},{"id":"c4a07c80.fd1ce","type":"function","z":"371b5d1c.9c46c2","name":"checking if lights are on","func":"msg.payload = {}\nmsg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'TAB PRESENCE ACTIONS AVISO: Chequeando si la luz de prueba esta encendida...';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":730,"y":400,"wires":[["f856ebfd.4deb38","e5c87795.fea4a8"]]},{"id":"5532d535.d91dec","type":"delay","z":"371b5d1c.9c46c2","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":680,"y":360,"wires":[["c4a07c80.fd1ce"]]},{"id":"2442976c.7ca968","type":"function","z":"371b5d1c.9c46c2","name":"out home","func":"msg.payload = {}\nmsg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'TAB PRESENCE ACTIONS AVISO: Estas fuera de casa.';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":320,"wires":[["5532d535.d91dec"]]},{"id":"2a598912.1e5436","type":"http request","z":"371b5d1c.9c46c2","name":"Apagar luz de prueba","method":"use","ret":"txt","paytoqs":"ignore","url":"http://192.168.1.165/cm?cmnd=Power%20off","tls":"","persist":false,"proxy":"","authType":"","x":940,"y":560,"wires":[[]]},{"id":"4a527deb.5836f4","type":"server-state-changed","z":"371b5d1c.9c46c2","name":"","server":"59ced628.1507a8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.luz_prueba_luz_prueba_2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":220,"y":580,"wires":[["97e430b6.11b36"]]},{"id":"e5c87795.fea4a8","type":"function","z":"371b5d1c.9c46c2","name":"light off","func":"msg.payload = {}\nmsg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'TAB PRESENCE ACTIONS AVISO: La luz estaba apagada, no hay de que preocuparse!...';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":900,"y":620,"wires":[[]]},{"id":"f856ebfd.4deb38","type":"function","z":"371b5d1c.9c46c2","name":"light on","func":"msg.payload = {}\nmsg.payload.chatId = 587232739;\nmsg.payload.type = 'message';\nmsg.payload.content = 'TAB PRESENCE ACTIONS AVISO: La luz estaba prendida, apagando luz...';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":900,"y":480,"wires":[["a10c8a09.c88748"]]},{"id":"a10c8a09.c88748","type":"delay","z":"371b5d1c.9c46c2","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":900,"y":520,"wires":[["2a598912.1e5436"]]},{"id":"97e430b6.11b36","type":"switch","z":"371b5d1c.9c46c2","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"not_home","vt":"str"},{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":470,"y":420,"wires":[["2442976c.7ca968"],["2442976c.7ca968"],["2442976c.7ca968"]]},{"id":"59ced628.1507a8","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false}]

Thanks a lot!

To help i will need a debug of the two Homme assistant nodes, these are not standard nodes and i have no idea what msg they produce.
second i would need a clear explanation of what you are attempting to do. As your flow makes no sense to me.

Do you realize that your function node 'checking if lights are on' is sending a message to both the 'light on' function node and the 'light off' function node?

Yes i've realized that, thanks in advance.

Ok. I've arrived to a point where i get a little confused or i'm not doing the right thing.

This is what i have so far...

  1. check whether im or not at home
  2. check if the light is on or off
  3. I put a "wait until" node because i want to have a precondition on every node before trigger the action.
  4. everything follows as it is....

....so here comes the problem...

If the location node says "home" and i turn on the light, it will turn it Off. Here is when it fails, because i want to turn on the light when im home and not to be turned off automaticaly...

Any clues?

Thanks a lot.

Can you provide the current flow?

As I don't have Home assistant, I'll offer some ideas. Put a debug node on the output of both Wait until nodes and one on the output of the 'enter home' function node. This will give an idea of what data is coming thru and when.

As an aside, since you are only building a message, you could replace your function nodes with template nodes like this

[{"id":"2540a245.1881de","type":"template","z":"521e528d.9304e4","name":"Enter Home","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\n    \"chatId\": 587232739,\n    \"type\" : \"message\",\n    \"content\" : \"TAB PRESENCE ACTIONS AVISO: Estas dentro de casa.\"\n }\n","output":"json","x":740,"y":180,"wires":[["b5d0bc54.d31738"]]}]

Ok...here is the debug node at the output of both Wait Until nodes. I have "mocked" up the nodes doing the same but if i'm at home, not away, so i can test the functionality and behavour being inside my home.

I didn't know about that template node. Thanks for that!.

(FYI when adding debug nodes, add a separate one for each place you want to debug AND name them. That way someone else can see exactly what node created each output in the log.)

So you are sending messages out to telegraph. What happens to those messages?
Also the 'checking if lights on' doesn't check anything but sends a msg directly to the telegraph node. mrsnehile another msg get's sent thru th edelay to the switch.

However since you didn't expand the data object in the log, I have no idea what it is doing. Can you expand them and show what they contain.

Ok, i think i found the solution just simplyfing the nodes by now.

Thanks a lot for the help!.