Simple presence trigger with home assistant

Hello,

I am new to Node Red and the event driven logic, but familiar with traditional programming.

As my first project, I want to do a simple presence tracker for two Home Assistant person instances, but somehow fail to get fundamental approach.

I want to trigger something when both persons are not home (for 10 minutes).

Two state_changed nodes emit either home, not_home or a name of a zone. My first approach is to use boolean-logic-ultimate use a boolean node and invert the OR output. That basically works, because

  • the boolean node saves the inputs, so that the events do not need to be together
  • it interprets home == true and not_home == false.

However, when I am at another zone, e.g. MyEmployer the output is undefined, though I want everything not home to be false. It seems that I need another node which does that translation for me.

I am bit surprised that I need so many nodes (including 3rd party) for a very simple task and think I am probably doing fundamentally something wrong.

What is the canonical way to do something like that?

Thanks a lot!

This is how my flow looks like (niemand daheim == nobody home)

when I am at another zone

What does "zone" mean in this context ?
Note that most users here do not home assistant, so we can only guess what your flow is doing.

I am bit surprised that I need so many nodes (including 3rd party) for a very simple task

I am suprised that you need a whole OS (home assistant) for all these simple tasks :wink:

3 Likes

What does "zone" mean in this context ?

A person has a state. This can be either home or not_home or a zone name. A zone is a defined geographical area, such as the area around your employers location, or your school, ... The state becomes the zone name, when in the person in the respective zone.

The zone name (or home, ...) is used as the payload in Node Red.

I basically want to formulate that:

(person.caro != "home") and (person.florian != "home").

The flow above does that, but only if !home == not_home, but any payload, besides home should be interpreted as false.

Thanks!

I have no idea what the output of the state_changed nodes is but assuming that the output includes person.x and either home or not_home or 'location' this is a bit crude but it works

[{"id":"c7e49db42498d1d2","type":"inject","z":"738628ae578a307b","name":"Caro Home","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"stateCaro","payload":"{\"person\":{\"caro\":\"home\"}}","payloadType":"json","x":1370,"y":1340,"wires":[["5348b284714d6d04"]]},{"id":"96a04894b4772f95","type":"inject","z":"738628ae578a307b","name":"Florian Not Home","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"stateFlorian","payload":"{\"person\" : {\"florian\" : \"not_home\"}}","payloadType":"json","x":1360,"y":1400,"wires":[["5348b284714d6d04"]]},{"id":"59056b385434cfb3","type":"inject","z":"738628ae578a307b","name":"Caro Not Home","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"stateCaro","payload":"{\"person\":{\"caro\":\"not_home\"}}","payloadType":"json","x":1360,"y":1300,"wires":[["5348b284714d6d04"]]},{"id":"996f9ed2a0375fc4","type":"inject","z":"738628ae578a307b","name":"Florian Home","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"stateFlorian","payload":"{\"person\":{\"florian\":\"home\"}}","payloadType":"json","x":1370,"y":1440,"wires":[["5348b284714d6d04"]]},{"id":"2ab29179dbb3cf8f","type":"inject","z":"738628ae578a307b","name":"Florian at Work","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"stateFlorian","payload":"{\"person\" : {\"florian\" : \"at_work\"}}","payloadType":"json","x":1380,"y":1480,"wires":[["5348b284714d6d04"]]},{"id":"5348b284714d6d04","type":"join","z":"738628ae578a307b","name":"","mode":"custom","build":"object","property":"payload.person","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1710,"y":1400,"wires":[["cf093039818bfd9b"]]},{"id":"cf093039818bfd9b","type":"change","z":"738628ae578a307b","name":"Home State","rules":[{"t":"set","p":"payload","pt":"msg","to":"$lookup(payload.person.stateCaro, \"caro\") = \"home\" and $lookup(payload.person.stateFlorian,\"florian\") = \"home\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1850,"y":1400,"wires":[["350d92ed1689db41"]]},{"id":"350d92ed1689db41","type":"debug","z":"738628ae578a307b","name":"Home, Not Home","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2110,"y":1400,"wires":[]}]
1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.