Home Assistant Community

Setting Home/Away functions via Node-RED

#1

Someone shoot holes through my plan. I want HA/Node-RED to be able to know when either my wife and I, or only one of us is home and set things that have a Home/Away mode to the correct setting.

This is where I have started and I’m not sure that it is working as intended. Thoughts?

[
{
    "id": "626a9eee.c0c4f",
    "type": "tab",
    "label": "Home/Away Controller",
    "disabled": false,
    "info": "Control Home/Away Devices"
},
{
    "id": "3dc6a01d.1f5c8",
    "type": "function",
    "z": "626a9eee.c0c4f",
    "name": "Is Anyone Home?",
    "func": "var jonathanLocation = global.get(\"jonathanLocation\");\nvar taylorLocation  = global.get(\"taylorLocation\");\n\nif (jonathanLocation != \"home\" && taylorLocation != \"home\") {\n    msg.payload = \"away\";\n    return msg;\n} else {\n    msg.payload = \"home\";\n    return msg;\n}\n",
    "outputs": 1,
    "noerr": 0,
    "x": 530,
    "y": 200,
    "wires": [
        [
            "933f60f8.57b86"
        ]
    ]
},
{
    "id": "8ef890b.0eede7",
    "type": "api-call-service",
    "z": "626a9eee.c0c4f",
    "name": "Nest: Away",
    "server": "92954ff.98a11b",
    "service_domain": "climate",
    "service": "set_away_mode",
    "data": "{ \"away_mode\": \"on\" }",
    "mergecontext": "",
    "x": 1010,
    "y": 220,
    "wires": [
        []
    ]
},
{
    "id": "6b3569c1.d0a388",
    "type": "api-call-service",
    "z": "626a9eee.c0c4f",
    "name": "Nest: Home",
    "server": "92954ff.98a11b",
    "service_domain": "climate",
    "service": "set_away_mode",
    "data": "{ \"away_mode\": \"off\" }",
    "mergecontext": "",
    "x": 1010,
    "y": 180,
    "wires": [
        []
    ]
},
{
    "id": "933f60f8.57b86",
    "type": "switch",
    "z": "626a9eee.c0c4f",
    "name": "Outputs for Home/Away",
    "property": "payload",
    "propertyType": "msg",
    "rules": [
        {
            "t": "eq",
            "v": "home",
            "vt": "str"
        },
        {
            "t": "eq",
            "v": "away",
            "vt": "str"
        }
    ],
    "checkall": "true",
    "repair": false,
    "outputs": 2,
    "x": 770,
    "y": 200,
    "wires": [
        [
            "6b3569c1.d0a388",
            "c82f3996.256f88"
        ],
        [
            "8ef890b.0eede7",
            "f2f77c20.5282"
        ]
    ]
},
{
    "id": "f2f77c20.5282",
    "type": "api-call-service",
    "z": "626a9eee.c0c4f",
    "name": "Arlo: Armed",
    "server": "92954ff.98a11b",
    "service_domain": "camera",
    "service": "enable_motion_detection",
    "data": "{ \"entity_id\": \"camera.front_window, camera.antuique_record_player\" }",
    "mergecontext": "",
    "x": 1010,
    "y": 360,
    "wires": [
        []
    ]
},
{
    "id": "c82f3996.256f88",
    "type": "api-call-service",
    "z": "626a9eee.c0c4f",
    "name": "Arlo: Disarmed",
    "server": "92954ff.98a11b",
    "service_domain": "camera",
    "service": "disable_motion_detection",
    "data": "{ \"entity_id\": \"camera.front_window, camera.antuique_record_player\" }",
    "mergecontext": "",
    "x": 1020,
    "y": 320,
    "wires": [
        []
    ]
},
{
    "id": "3dfe2afa.47a106",
    "type": "comment",
    "z": "626a9eee.c0c4f",
    "name": "Set Nest Home/Away",
    "info": "",
    "x": 1040,
    "y": 140,
    "wires": []
},
{
    "id": "1b98b668.7390aa",
    "type": "comment",
    "z": "626a9eee.c0c4f",
    "name": "Arm/Disarm Arlo",
    "info": "",
    "x": 1020,
    "y": 280,
    "wires": []
},
{
    "id": "e9c44549.b2ce78",
    "type": "server-state-changed",
    "z": "626a9eee.c0c4f",
    "name": "Jonathan Location",
    "server": "92954ff.98a11b",
    "entityidfilter": "device_tracker.google_maps_****",
    "entityidfiltertype": "substring",
    "haltifstate": "",
    "x": 110,
    "y": 180,
    "wires": [
        [
            "6c88db56.d56e44"
        ]
    ]
},
{
    "id": "5df57d77.685084",
    "type": "server-state-changed",
    "z": "626a9eee.c0c4f",
    "name": "Taylor Location",
    "server": "92954ff.98a11b",
    "entityidfilter": "device_tracker.google_maps_****",
    "entityidfiltertype": "substring",
    "haltifstate": "",
    "x": 120,
    "y": 220,
    "wires": [
        [
            "a8c9173c.21c638"
        ]
    ]
},
{
    "id": "6c88db56.d56e44",
    "type": "function",
    "z": "626a9eee.c0c4f",
    "name": "jonathanLocation",
    "func": "global.set(\"jonathanLocation\", msg.data.new_state.state);\nconsole.log(\"Jonathan's location changed...\");",
    "outputs": 1,
    "noerr": 0,
    "x": 310,
    "y": 180,
    "wires": [
        [
            "3dc6a01d.1f5c8"
        ]
    ]
},
{
    "id": "a8c9173c.21c638",
    "type": "function",
    "z": "626a9eee.c0c4f",
    "name": "taylorLocation",
    "func": "global.set(\"taylorLocation\", msg.data.new_state.state);\nconsole.log(\"Taylors location changed...\")",
    "outputs": 1,
    "noerr": 0,
    "x": 320,
    "y": 220,
    "wires": [
        [
            "3dc6a01d.1f5c8"
        ]
    ]
},
{
    "id": "92954ff.98a11b",
    "type": "server",
    "z": "",
    "name": "homeassistant",
    "url": "http://192.168.0.250:8123",
    "pass": "****"
}
]

Also here is a photo of the flow so you can see the “wiring”:

#2

I have the below setup … I had Bluetooth signal dropouts thats why delay 60sec and check if the status is still away before setting my boolean to true (in node TS left &Mum left)

I use a boolean for each family member and than can easily check and set the away boolean

#3

Mine is similar to xx_Nexus_xx.

Im not sure why you need to use the globals/functions. You can use the current state node to pull the state directly from homeassistant.

#4

yes, I’m aware … I’m using the globals/functions so I can see the state changes directly in the frontend

#5

Hello,

Nice job ! Is it possible to have un export of the Trigger node ? Just in order to understand how it works, because mine are not working … :frowning:

Thanks !

#6

Here you go

[
    {
        "id": "2813fefc.7a7be2",
        "type": "trigger-state",
        "z": "96100229.c25d8",
        "name": "Home Set From Away to Home",
        "server": "21a5d722.1a2e58",
        "entityid": "input_select.home_mode",
        "debugenabled": false,
        "constraints": [
            {
                "id": "drck1l2wgz",
                "targetType": "this_entity",
                "targetValue": "",
                "propertyType": "current_state",
                "propertyValue": "new_state.state",
                "comparatorType": "is",
                "comparatorValueDatatype": "str",
                "comparatorValue": "Home"
            },
            {
                "id": "nx8sbykibq",
                "targetType": "this_entity",
                "targetValue": "",
                "propertyType": "previous_state",
                "propertyValue": "old_state.state",
                "comparatorType": "is",
                "comparatorValueDatatype": "str",
                "comparatorValue": "Away"
            }
        ],
        "constraintsmustmatch": "all",
        "outputs": 2,
        "customoutputs": [],
        "x": 175,
        "y": 607,
        "wires": [
            [
                "437aa889.e96cb8",
                "aac501e5.4e55"
            ],
            []
        ]
    },
    {
        "id": "21a5d722.1a2e58",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "url": "",
        "pass": ""
    }
]
#7

Many Thanks !

#8

@nicp, would it possible to post the code for your 4 flows, I don’t fully understand how to create a home mode and then set it to home or away. Thanks!

#9

Sorry for the newbie question but what are these nodes you are using?

image

#10

These are the api-current-state nodes, I’m using the older non websockets version

#11

Hi bwanajag, is there something specifically you are having trouble with?

I’m using an older version so this code may not help you much.

[
{
    "id": "87a22e69.27778",
    "type": "api-call-service",
    "z": "96100229.c25d8",
    "name": "Set Home Mode Home",
    "server": "21a5d722.1a2e58",
    "service_domain": "input_select",
    "service": "select_option",
    "data": "{ \"entity_id\":\"input_select.home_mode\", \"option\":\"Home\"  }",
    "mergecontext": "",
    "x": 1030,
    "y": 260,
    "wires": [
        []
    ]
},
{
    "id": "6c3a2160.17bd7",
    "type": "api-call-service",
    "z": "96100229.c25d8",
    "name": "Set Home Mode Away",
    "server": "21a5d722.1a2e58",
    "service_domain": "input_select",
    "service": "select_option",
    "data": "{ \"entity_id\":\"input_select.home_mode\", \"option\":\"Away\"  }",
    "mergecontext": "",
    "x": 1020,
    "y": 420,
    "wires": [
        []
    ]
},
{
    "id": "e11c9185.2ada3",
    "type": "trigger-state",
    "z": "96100229.c25d8",
    "name": "Nic iPhone away to home",
    "server": "21a5d722.1a2e58",
    "entityid": "device_tracker.nics_iphone",
    "debugenabled": false,
    "constraints": [
        {
            "id": "3wz11os97jh",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "current_state",
            "propertyValue": "new_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "home"
        },
        {
            "id": "wbmz063xpn",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "previous_state",
            "propertyValue": "old_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "not_home"
        }
    ],
    "constraintsmustmatch": "all",
    "outputs": 2,
    "customoutputs": [],
    "x": 150,
    "y": 320,
    "wires": [
        [
            "6482e5eb.5ca6cc",
            "8f9bf4ef.a96ed8"
        ],
        []
    ]
},
{
    "id": "59948012.5eb79",
    "type": "trigger-state",
    "z": "96100229.c25d8",
    "name": "Nic iPhone home to not_home",
    "server": "21a5d722.1a2e58",
    "entityid": "device_tracker.nics_iphone",
    "debugenabled": false,
    "constraints": [
        {
            "id": "nfrzw9ya7n",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "previous_state",
            "propertyValue": "old_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "home"
        },
        {
            "id": "kpadvctzfrj",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "current_state",
            "propertyValue": "new_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "not_home"
        }
    ],
    "constraintsmustmatch": "all",
    "outputs": 2,
    "customoutputs": [],
    "x": 170,
    "y": 460,
    "wires": [
        [
            "37f76f71.43a13"
        ],
        []
    ]
},
{
    "id": "66ab6408.2355fc",
    "type": "trigger-state",
    "z": "96100229.c25d8",
    "name": "Anna iPhone away to home",
    "server": "21a5d722.1a2e58",
    "entityid": "device_tracker.annas_iphone",
    "debugenabled": false,
    "constraints": [
        {
            "id": "3wz11os97jh",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "current_state",
            "propertyValue": "new_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "home"
        },
        {
            "id": "q1ce0fqwnw",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "previous_state",
            "propertyValue": "old_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "not_home"
        }
    ],
    "constraintsmustmatch": "all",
    "outputs": 2,
    "customoutputs": [],
    "x": 160,
    "y": 260,
    "wires": [
        [
            "6482e5eb.5ca6cc",
            "8f9bf4ef.a96ed8"
        ],
        []
    ]
},
{
    "id": "e89665b6.bab888",
    "type": "trigger-state",
    "z": "96100229.c25d8",
    "name": "Anna iPhone home to not_home",
    "server": "21a5d722.1a2e58",
    "entityid": "device_tracker.annas_iphone",
    "debugenabled": false,
    "constraints": [
        {
            "id": "nfrzw9ya7n",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "previous_state",
            "propertyValue": "old_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "home"
        },
        {
            "id": "1xl0ty2k8ej",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "current_state",
            "propertyValue": "new_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "not_home"
        }
    ],
    "constraintsmustmatch": "all",
    "outputs": 2,
    "customoutputs": [],
    "x": 170,
    "y": 400,
    "wires": [
        [
            "a288855e.bcc958"
        ],
        []
    ]
},
{
    "id": "d2c1c15e.e3e35",
    "type": "switch",
    "z": "96100229.c25d8",
    "name": "Home/Away/Hold",
    "property": "payload",
    "propertyType": "msg",
    "rules": [
        {
            "t": "eq",
            "v": "Home",
            "vt": "str"
        },
        {
            "t": "eq",
            "v": "Away",
            "vt": "str"
        },
        {
            "t": "eq",
            "v": "Hold",
            "vt": "str"
        }
    ],
    "checkall": "true",
    "repair": false,
    "outputs": 3,
    "x": 730,
    "y": 260,
    "wires": [
        [],
        [
            "87a22e69.27778"
        ],
        []
    ]
},
{
    "id": "6482e5eb.5ca6cc",
    "type": "api-current-state",
    "z": "96100229.c25d8",
    "name": "Home Mode",
    "server": "21a5d722.1a2e58",
    "halt_if": "",
    "override_topic": true,
    "override_payload": true,
    "entity_id": "input_select.home_mode",
    "x": 450,
    "y": 260,
    "wires": [
        [
            "d2c1c15e.e3e35"
        ]
    ]
},
{
    "id": "37f76f71.43a13",
    "type": "api-current-state",
    "z": "96100229.c25d8",
    "name": "Anna iPhone not home",
    "server": "21a5d722.1a2e58",
    "halt_if": "home",
    "override_topic": true,
    "override_payload": true,
    "entity_id": "device_tracker.annas_iphone",
    "x": 420,
    "y": 460,
    "wires": [
        [
            "915aaf18.5118a"
        ]
    ]
},
{
    "id": "a288855e.bcc958",
    "type": "api-current-state",
    "z": "96100229.c25d8",
    "name": "Nic iPhone not home",
    "server": "21a5d722.1a2e58",
    "halt_if": "home",
    "override_topic": true,
    "override_payload": true,
    "entity_id": "device_tracker.nics_iphone",
    "x": 420,
    "y": 400,
    "wires": [
        [
            "915aaf18.5118a"
        ]
    ]
},
{
    "id": "915aaf18.5118a",
    "type": "api-current-state",
    "z": "96100229.c25d8",
    "name": "Home Mode",
    "server": "21a5d722.1a2e58",
    "halt_if": "",
    "override_topic": true,
    "override_payload": true,
    "entity_id": "input_select.home_mode",
    "x": 630,
    "y": 420,
    "wires": [
        [
            "9ff493d6.66d07"
        ]
    ]
},
{
    "id": "9ff493d6.66d07",
    "type": "switch",
    "z": "96100229.c25d8",
    "name": "Home/Away/Hold",
    "property": "payload",
    "propertyType": "msg",
    "rules": [
        {
            "t": "eq",
            "v": "Home",
            "vt": "str"
        },
        {
            "t": "eq",
            "v": "Away",
            "vt": "str"
        },
        {
            "t": "eq",
            "v": "Hold",
            "vt": "str"
        }
    ],
    "checkall": "true",
    "repair": false,
    "outputs": 3,
    "x": 810,
    "y": 420,
    "wires": [
        [
            "6c3a2160.17bd7"
        ],
        [],
        []
    ]
},
{
    "id": "cf380a7d.42c188",
    "type": "comment",
    "z": "96100229.c25d8",
    "name": "Auto mode from iPhones",
    "info": "",
    "x": 150,
    "y": 200,
    "wires": []
},
{
    "id": "a9875210.05ccd",
    "type": "comment",
    "z": "96100229.c25d8",
    "name": "Actions on Away and Home",
    "info": "",
    "x": 160,
    "y": 560,
    "wires": []
},
{
    "id": "2813fefc.7a7be2",
    "type": "trigger-state",
    "z": "96100229.c25d8",
    "name": "Home Set From Away to Home",
    "server": "21a5d722.1a2e58",
    "entityid": "input_select.home_mode",
    "debugenabled": false,
    "constraints": [
        {
            "id": "drck1l2wgz",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "current_state",
            "propertyValue": "new_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "Home"
        },
        {
            "id": "nx8sbykibq",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "previous_state",
            "propertyValue": "old_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "Away"
        }
    ],
    "constraintsmustmatch": "all",
    "outputs": 2,
    "customoutputs": [],
    "x": 175,
    "y": 607,
    "wires": [
        [
            "437aa889.e96cb8",
            "aac501e5.4e55"
        ],
        []
    ]
},
{
    "id": "634c1c33.1901f4",
    "type": "trigger-state",
    "z": "96100229.c25d8",
    "name": "Home Set to Home",
    "server": "21a5d722.1a2e58",
    "entityid": "input_select.home_mode",
    "debugenabled": false,
    "constraints": [
        {
            "id": "pr9vnybcye",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "current_state",
            "propertyValue": "new_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "Home"
        }
    ],
    "constraintsmustmatch": "all",
    "outputs": 2,
    "customoutputs": [],
    "x": 130,
    "y": 740,
    "wires": [
        [
            "1d11800b.149dd",
            "b80a91d9.01019"
        ],
        []
    ]
},
{
    "id": "e7e851cb.5c383",
    "type": "trigger-state",
    "z": "96100229.c25d8",
    "name": "Home Set to Away",
    "server": "21a5d722.1a2e58",
    "entityid": "input_select.home_mode",
    "debugenabled": false,
    "constraints": [
        {
            "id": "vxso2k2o8h",
            "targetType": "this_entity",
            "targetValue": "",
            "propertyType": "current_state",
            "propertyValue": "new_state.state",
            "comparatorType": "is",
            "comparatorValueDatatype": "str",
            "comparatorValue": "Away"
        }
    ],
    "constraintsmustmatch": "all",
    "outputs": 2,
    "customoutputs": [],
    "x": 130,
    "y": 860,
    "wires": [
        [
            "1aa588af.03ff67",
            "b3e3f034.c513",
            "3d35ff86.af274",
            "ca41867f.3473e8",
            "4a084f80.0ba85",
            "957e0baa.20e808"
        ],
        []
    ]
},
{
    "id": "330d4410.adc65c",
    "type": "comment",
    "z": "96100229.c25d8",
    "name": "Prevents changing thermostat on Hold->Home",
    "info": "",
    "x": 220,
    "y": 660,
    "wires": []
},
{
    "id": "21a5d722.1a2e58",
    "type": "server",
    "z": "",
    "name": "Home Assistant",
    "url": "http://url",
    "pass": "pass"
}

]

#12

Ah yes. mine looks more like a plane then an arrow. Thanks

#13

@nicp I noticed in the call service node “Set Home Mode Home” that you had an entity ID of input_select.home_mode. How/where did you create this entity? I’ve not done this before, not sure where to start.

Also, for your switches, what is the use case of “Hold”? Is this when someone is away but you want it to act like someone’s home?

#14

Hi bwanajag,

This page explains how to setup an input_select in home assistant https://www.home-assistant.io/components/input_select/

The yaml I use is:

input_select:
  home_mode:
    name: Home Mode
    options:
     - Home
     - Away
     - Hold
    initial: Home
    icon: mdi:house

The home and away mode are triggered by if our mobile devices are present, the hold mode is used to disable the automations when we leave the house with a guest over (stops everything automatically turning off when we leave).