I have created and automation that sees a device tracker when it comes home it turns on input_boolean to set the home to occupied and when we leave turns to unoccupied. Here is my opportunity once either my wife or I get home garage opens and turns on TV. I have a problem when one of us leaves the house it does not recognize that the other person is still in the house and turns off the automation. Any suggestions would be greatly appreicated.
Could you let us see the automation you have at the moment?
[
{
"id": "8abcfea2ada2bc44",
"type": "tab",
"label": "Home",
"disabled": false,
"info": "",
"env": []
},
{
"id": "827f6729676e307c",
"type": "api-call-service",
"z": "8abcfea2ada2bc44",
"name": "Living Room TV on",
"server": "38773d8d.4339f2",
"version": 5,
"debugenabled": true,
"domain": "media_player",
"service": "turn_on",
"areaId": [],
"deviceId": [
"9bdfc8da4937e502b8686636d8d3ae15"
],
"entityId": [],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 350,
"y": 240,
"wires": [
[]
]
},
{
"id": "d1828b48eee4f575",
"type": "api-call-service",
"z": "8abcfea2ada2bc44",
"name": "Living Room TV Off",
"server": "38773d8d.4339f2",
"version": 5,
"debugenabled": true,
"domain": "media_player",
"service": "turn_off",
"areaId": [],
"deviceId": [
"9bdfc8da4937e502b8686636d8d3ae15"
],
"entityId": [],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 630,
"y": 100,
"wires": [
[]
]
},
{
"id": "548b5f06890bb186",
"type": "server-state-changed",
"z": "8abcfea2ada2bc44",
"name": "Derek Home",
"server": "38773d8d.4339f2",
"version": 5,
"outputs": 2,
"exposeAsEntityConfig": "",
"entityId": "input_boolean.derek",
"entityIdType": "exact",
"outputInitially": false,
"stateType": "str",
"ifState": "off",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": false,
"for": "0",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
}
],
"x": 110,
"y": 20,
"wires": [
[
"8128cda5ba9f07ee"
],
[]
]
},
{
"id": "e08a667f9f2e5fbe",
"type": "server-state-changed",
"z": "8abcfea2ada2bc44",
"name": "Melissa Home",
"server": "38773d8d.4339f2",
"version": 5,
"outputs": 2,
"exposeAsEntityConfig": "",
"entityId": "input_boolean.melissa",
"entityIdType": "substring",
"outputInitially": false,
"stateType": "str",
"ifState": "off",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": false,
"for": "0",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
}
],
"x": 110,
"y": 80,
"wires": [
[
"ccf6c1a2f06fe183"
],
[]
]
},
{
"id": "8128cda5ba9f07ee",
"type": "api-current-state",
"z": "8abcfea2ada2bc44",
"name": "Melissa Home",
"server": "38773d8d.4339f2",
"version": 3,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_boolean.melissa",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": 0,
"forType": "num",
"forUnits": "minutes",
"x": 340,
"y": 20,
"wires": [
[
"5f73ff31.c13f3"
],
[]
]
},
{
"id": "ccf6c1a2f06fe183",
"type": "api-current-state",
"z": "8abcfea2ada2bc44",
"name": "Derek Home",
"server": "38773d8d.4339f2",
"version": 3,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "input_boolean.derek",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": 0,
"forType": "num",
"forUnits": "minutes",
"x": 330,
"y": 80,
"wires": [
[
"5f73ff31.c13f3"
],
[]
]
},
{
"id": "ad77303fe2f589e9",
"type": "server-state-changed",
"z": "8abcfea2ada2bc44",
"name": "Derek Home",
"server": "38773d8d.4339f2",
"version": 5,
"outputs": 2,
"exposeAsEntityConfig": "",
"entityId": "input_boolean.derek",
"entityIdType": "exact",
"outputInitially": false,
"stateType": "str",
"ifState": "on",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": false,
"for": "0",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
}
],
"x": 110,
"y": 160,
"wires": [
[
"8762ebb51cdaea2f"
],
[]
]
},
{
"id": "8b045392a66cc083",
"type": "server-state-changed",
"z": "8abcfea2ada2bc44",
"name": "Melissa Home",
"server": "38773d8d.4339f2",
"version": 5,
"outputs": 2,
"exposeAsEntityConfig": "",
"entityId": "input_boolean.melissa",
"entityIdType": "exact",
"outputInitially": false,
"stateType": "str",
"ifState": "on",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": false,
"for": "0",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [],
"x": 110,
"y": 220,
"wires": [
[
"8762ebb51cdaea2f"
],
[]
]
},
{
"id": "5f73ff31.c13f3",
"type": "api-call-service",
"z": "8abcfea2ada2bc44",
"name": "Away",
"server": "38773d8d.4339f2",
"version": 5,
"debugenabled": true,
"domain": "input_boolean",
"service": "turn_off",
"areaId": [],
"deviceId": [],
"entityId": [
"input_boolean.home_occupied"
],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 590,
"y": 20,
"wires": [
[
"d1828b48eee4f575"
]
]
},
{
"id": "8762ebb51cdaea2f",
"type": "api-call-service",
"z": "8abcfea2ada2bc44",
"name": "Away",
"server": "38773d8d.4339f2",
"version": 5,
"debugenabled": false,
"domain": "input_boolean",
"service": "turn_on",
"areaId": [],
"deviceId": [],
"entityId": [
"input_boolean.home_occupied"
],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 310,
"y": 160,
"wires": [
[
"827f6729676e307c"
]
]
},
{
"id": "38773d8d.4339f2",
"type": "server",
"name": "Home Assistant",
"addon": true,
"rejectUnauthorizedCerts": true,
"ha_boolean": "",
"connectionDelay": false,
"cacheJson": false,
"heartbeat": false,
"heartbeatInterval": "",
"statusSeparator": "",
"enableGlobalContextStore": false
}
]
That doesnt looks like an automation code.
Search the automation and post the yaml (settings - automations - search the one - then on the three dots upper right select âEdit in YAMLâ , copy and paste here.
I created the automation in Nodered that is the node exported.
Ah the automation section is for the builtin automations. There is a node red specific section - you may want to re-categorize your post for better visibility. (I did that for you)
That said look at the numeric state of the home zone. It contains the current count of person objects with device trackers reporting home in that zone. - basically if itâs >= 1 home is occupied. Do the thing. If itâs =0 vacant donât do the thing.
Thanks for your help in moving to the NR section.
There are several ways to achieve this, but ultimately you need to test both your âinput_booleanâ switches for âoffâ at the same time, not individually.
You can use the events: state node entity as a list, so it will respond to either input Boolean switch changing state. The test condition will only pass the message when either trigger shows the switch going to âoffâ. Then you can add a bit of JSONata in the output to read the state of both switches and to pass âtrueâ if both are âoffâ. A simple switch node can then test for this case - and therefore only pass a message if either switch goes to âoffââ and both switches are âoffâ.
I cannot set this up myself so this has been hand edited with your values. It should work.
[
{
"id": "548b5f06890bb186",
"type": "server-state-changed",
"z": "8abcfea2ada2bc44",
"name": "Derek or Melissa Leaves",
"server": "84a75071b624414a",
"version": 5,
"outputs": 2,
"exposeAsEntityConfig": "",
"entityId": [
"input_boolean.derek",
"input_boolean.melissa"
],
"entityIdType": "list",
"outputInitially": false,
"stateType": "str",
"ifState": "off",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": false,
"for": "0",
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "$entities('input_boolean.derek').state = \"off\" and $entities('input_boolean.melissa').state = \"off\"",
"valueType": "jsonata"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
}
],
"x": 330,
"y": 160,
"wires": [
[
"401e7b6475225d28"
],
[]
]
},
{
"id": "401e7b6475225d28",
"type": "switch",
"z": "8abcfea2ada2bc44",
"name": "Both Away",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "true"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 550,
"y": 160,
"wires": [
[]
]
}
]
Here is a screen shot of my flow. Do I need to modify it show the input is managed through the state node you created that puts Derek or Melissa leaves?
If you use the below in a trigger state node, the 1st ouptut will only happen if both are âoffâ otherwise the 2nd output will be used.
You can then turn the TV off/on linking to the appropriate output.
If I read your flow correctly, the pair of nodes should replace all of the top left four in your flow, and can go straight to your âawayâ and âliving room tv offâ service call nodes.
I would suggest that you try and keep the names of your nodes correct for what they are doing - you have nodes called âHomeâ and âAwayâ for both leaving and arriving and it is difficult to read.
@mikep99 is correct that a trigger node can be used to do this, and that would probably be the best answer for you here. How you do something like this depends on personal choice - the trigger node is powerful, but the condition tests are all âANDâ, which is fine in your case, but for âORâ conditions it is necessary to use JSONata to perform the conditional test. For myself, I like to use JSONata when I can.
There are other ways that you could improve on this flow, however getting it to work is the first key step and then you can come back and improve it later.
It looked good on paper but for some reason it did not work. If I click either of the input_boolean.derek or input_boolean.melissa independently it still turns off the TV and Away is activated. The Home seems to work just fine.
Any suggestions?
Since zones was updated, there is a new entity called zone.home
, that is what @NathanCu is referencing. Rather than use input booleans to mark weather you are home or not create a person in HA for each of you.
For each person add their device tracker/s. You do not need to use gps unless you want to. I use a bluetooth and wifi sensor.
Once that is done zone.home
will return a number of how many persons are home. So >= 1
someone is home. < 1
no one is home.
I am not sure if I have missed something or not. But I have tried to make this a simple as you guys have shown me. In my zone.home it shows (2) persons (person.derek) & (person.melissa). I have setup the events state node that when the zone.home is <1 turn off the TV. If I go to the developers tools and change state from Home to Away on both device trackers Living Room TV does not get triggered. But below the events state node there is s little red 2 underneath.
Change the state of zone.home
to 0
. It does not have a state of home or away, it will always be a number. It is a count of how many people are home.
So lets try to have you guys give me the best way to achieve my goals. I am still new to this whole âHA & NRâ interaction.
Goal #1
When myself or my wife comes home turn on âLiving Room TVâ since we usually do not come home at the same time I need to make sure when the other party comes home that the automation to turn on âLiving Room TVâ does not get duplicated and then turn off TV.
Goal #2
When both of us leave turn off âLiving Room TVâ but once again we usually do not leave at the same time so if one of us leaves do not turn off TV until both parties are gone. Sometimes one of us maybe be home and the other party may go to the store and come back so we donât want to duplicate a automation when they leave and come back while the other party was home the whole time.
You can disregard anything I have already started if you feel I am not headed down the best path.
Mikeâs solution above already does this.
Youâre fighting two concepts here.
First the concept of whole home occupancy.
You do this as described by adding trackers to person objecs and then tracking the numeric state of the home zone.
All the this should be setup and WORKING (at least reviewing dev tools - you should be able to see the count.
Once all this is setup you either use builtin automations or in this case node red. You chose node red.
This flow will start on a numeric state for the home zone. State changes will be sent. Iâd probably put a condition node with options for >=1, <1, and error state. Your greater than branch is home. Trigger your return stuff. Other branch is away. Trigger the away.
Make sure all the first part works before you try to setup the node red flow to respond to it. Have you made sure that part works?
To Everybody who assisted thanks. I was able to setup the automation with just (3) nodes. Wow. Now that I finally was able to get that up and running would love to have more insight on some of your automations you use for your house.
Looking for a little help. Just did the latest update and now my NR / HA automation is no longer working. I was using zone.home to trigger turning on / off my TV based on if there was anybody home. It used to show how many people were home based on a numeric value in the zone.home. Now it just shows running all the time. If I change the If state <=1 it turns off the TV. If I change it to =>1 it turns it back on like it is supposed to. Why would the zone.home state not be working anymore? I also have the âIgnore state change event when:â Current state equals previous state. âTickedâ