Hass_turn_all_off_except
Hass_turn_all_off_except
Usage
This flow supports the Home Assistant Lights Control and Home Assistant via Node-Red app. in Snips app store.
It is used to turn off a group of predefined entities and command one or two entities to be maintained or turned into the "on" state in homeassistant.
It handles the intent produced by Snips.AI assistant, it extracts the needed values and triggers a homeassistant turn-off for the predefined group and a homeassistant turn_on service for the entities commanded.
Requirements
Home Assistant with some switch/light/group entities.
Node-Red as an add-on.
Snips.AI as an add-on with "Home Assistant via Node-Red" app added in your assistant.
Note: This flow works when Node-Red and Snips run as addons in Home Assistant. It can work in a satelite device as well with a some changes though. The satelite flow will be uploaded as a different flow.
Installation
Node-Red
To intall the flow download the zip and extract it. Open the flow with your favorite editor, copy the content and paste it in the Import/clipboard tab in Node-Red.
Reconfigure the flow.
Read the comments nodes to guide you through this process.
Read in each node the Description tab as well for a brief node explanation.
Snips.AI
Add the app "Home Assistant via Node-Red" in your assistant.
If you haven't done it already:
Edit the slot "entity_name".
In this slot enter the names of the entities you have in your homeassistant config.yaml and group.yaml . Note that they should be added as slot values and not synonyms. Synonyms can be added but they will point to the slot value, so be sure you have entered the names as found in your .yaml files.
Delete values that you don't use from the ones that already in the slot.
Edit the training examples and re-configure to include the names of your entities.
Download and install your assistant.
Home Assistant
In your home assistant config.yaml enable snips component
snips:
In your home assistant config.yaml (or intent_script.yaml if you have split things up) add the following.
intent_script:
turnalloffexcept:
speech:
type: plain
text: 'done'
Note: If you have changed the intent name, re-configure the above to match.
Note: Adding a text into your config.yaml for each intent is important. It will speed up the overall process. If you don't want any kind off feedback just play an empty text. (text: ' ')
[{"id":"ff77036c.b7acd","type":"tab","label":"turn_all_off_except","disabled":false,"info":"This flow when triggered from the turnalloffexcept\nintent produced by Snips assistant will start "},{"id":"8e07f55b.4b3fa8","type":"mqtt in","z":"ff77036c.b7acd","name":"mqtt listen (turn_all_off_except)","topic":"hermes/intent/nik_poz:turnalloffexcept","qos":"2","datatype":"auto","broker":"e92d1794.a4b0d8","x":139,"y":254,"wires":[["8d46e2a.3dc892"]],"info":"This node listens for the turnalloffexcept intent.\n(as found in the app.)\nYou must reconfigure this node:\n\n1)Edit server configuration and replace \nusername and password with yours\n\n2)You will also have to replace the topic with the\none produced by your assistant.\n"},{"id":"8d46e2a.3dc892","type":"yaml","z":"ff77036c.b7acd","property":"payload","name":"","x":341,"y":255,"wires":[["fc9302cc.7361b","f861fc18.5573c"]]},{"id":"fc9302cc.7361b","type":"switch","z":"ff77036c.b7acd","name":"path for msg1","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":127,"y":353,"wires":[["ba71777d.4ca658"]],"info":"In this nodes we just divide the message into 2 \nidentical messages.\n\nThe first will trigger the turn_off service and one of\nthe two turn_on services we can command in the intent.\nthe second will create a path for the second entity if\nany.\n\nNothing to configure in this node"},{"id":"f861fc18.5573c","type":"switch","z":"ff77036c.b7acd","name":"path for msg2","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":118,"y":404,"wires":[["e3b2f543.610b08"]],"info":"In this nodes we just divide the message into 2 \nidentical messages.\n\nThe first will trigger the turn_off service and one of\nthe two turn_on services we can command in the intent.\nthe second will create a path for the second entity if\nany.\n\nNothing to configure in this node"},{"id":"ba71777d.4ca658","type":"change","z":"ff77036c.b7acd","name":"msg.topic: 1","rules":[{"t":"set","p":"topic","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":353,"wires":[["eeaea45c.4b67b8","164c9163.411d4f"]],"info":" This node is used to set a temporary msg.topic\nfor each of the messages. \n\nHere we set msg.topic: 1"},{"id":"e3b2f543.610b08","type":"change","z":"ff77036c.b7acd","name":"msg.topic: 2","rules":[{"t":"set","p":"topic","pt":"msg","to":"2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":331,"y":405,"wires":[["dea1d069.b98eb"]],"info":" This node is used to set a temporary msg.topic\nfor each of the messages. \n\nHere we set msg.topic: 2"},{"id":"eeaea45c.4b67b8","type":"switch","z":"ff77036c.b7acd","name":"path for turn_off msg","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":526,"y":295,"wires":[["270d4a6f.85a346"]],"info":"In this node we will create the message for the \nturn_off service\n\nNothing to configure in this node"},{"id":"270d4a6f.85a346","type":"change","z":"ff77036c.b7acd","name":"group to turn_off","rules":[{"t":"set","p":"topic","pt":"msg","to":"{ \"domain\": \"homeassistant\", \"service\": \"turn_off\", \"data\": { \"entity_id\": \"group.groundfloorlights\" }}","tot":"json"},{"t":"set","p":"payload","pt":"msg","to":"topic","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":" ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":733,"y":295,"wires":[["fc10f80d.f3dd58","3cef8672.a39a5a"]],"info":"This node needs some configuration.\nYou will have to edit msg.topic in Properties tab\nand replace \"group.groundfloorlights\" with the group of \nentities you would like to turn_off.\n\n"},{"id":"fc10f80d.f3dd58","type":"api-call-service","z":"ff77036c.b7acd","name":"turn_off service","server":"4bbac141.a7708","service_domain":"homeassistant","service":"","data":"","mergecontext":"","output_location":"","output_location_type":"none","x":848,"y":198,"wires":[[]],"info":"This node calls the \"turn_off\" service \n\n\nNothing else to configure in this node"},{"id":"de8a69ff.02e808","type":"change","z":"ff77036c.b7acd","name":"move values to msg.payload","rules":[{"t":"delete","p":"payload.sessionId","pt":"msg"},{"t":"delete","p":"payload.customData","pt":"msg"},{"t":"delete","p":"payload.siteId","pt":"msg"},{"t":"delete","p":"payload.input","pt":"msg"},{"t":"delete","p":"payload.asrTokens","pt":"msg"},{"t":"delete","p":"payload.asrConfidence","pt":"msg"},{"t":"delete","p":"payload.intent","pt":"msg"},{"t":"delete","p":"payload.slots","pt":"msg"},{"t":"delete","p":"qos","pt":"msg"},{"t":"delete","p":"retain","pt":"msg"},{"t":"delete","p":"_topic","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"topic","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":624,"y":512,"wires":[["9f047e0d.8f789","7bacd63e.a200e8"]],"info":"In this node some more not needed values are deleted.\nmsg.topic is moved in msg.payload leaving \na blank msg.topic.\n\nNothing to configure in this node."},{"id":"cf64a1dc.2cde","type":"change","z":"ff77036c.b7acd","name":"Delete extra values not used in messages","rules":[{"t":"set","p":"topic","pt":"msg","to":"{ \"domain\": \"switch\", \"service\": \"turn_on\", \"data\": { \"entity_id\": \"light.secret_led_two\" }}","tot":"json"},{"t":"change","p":"payload.intent.intentName","pt":"msg","from":"nik_poz:turnalloffexcept","fromt":"str","to":"turn_on","tot":"str"},{"t":"change","p":"payload.slots[0].value.value","pt":"msg","from":" ","fromt":"str","to":"_","tot":"str"},{"t":"change","p":"topic.domain","pt":"msg","from":"switch","fromt":"str","to":"homeassistant","tot":"str"},{"t":"change","p":"topic.service","pt":"msg","from":"topic.service","fromt":"msg","to":"payload.intent.intentName","tot":"msg"},{"t":"change","p":"topic.data.entity_id","pt":"msg","from":"topic.data.entity_id","fromt":"msg","to":"payload.slots[0].value.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":197,"y":513,"wires":[["de8a69ff.02e808","318bbb94.2dd484"]],"info":"nik_poz:turnalloffexcept\nIn this node we collect the needed values and alter \nthem so we can produce a turn_on service\naccordingly.\n\nWe are also setting up on msg.topic the message\nformat that we will use to trigger a \nhomeassistant turn_on service.\n All content of the msg.topic will become \n msg.payload later on in the process.\n\nThis node needs to be changed.\nSearch in Prorerties tab and replace only\n \"nik_poz:turnalloffexcept\" with the intent name produced \nby your assistant\n"},{"id":"9f047e0d.8f789","type":"switch","z":"ff77036c.b7acd","name":"Seperation","property":"payload.data.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"kitchen_main_light","vt":"str"},{"t":"eq","v":"tv_porch_1","vt":"str"},{"t":"eq","v":"tv_porch_2","vt":"str"},{"t":"eq","v":"living_room_main","vt":"str"},{"t":"eq","v":"living_room_main1","vt":"str"},{"t":"eq","v":"hallway","vt":"str"},{"t":"eq","v":"toilet_light","vt":"str"},{"t":"eq","v":"toilet_fan","vt":"str"},{"t":"eq","v":"tv_secret_lights","vt":"str"},{"t":"eq","v":"tv_porch_light_1","vt":"str"},{"t":"eq","v":"tv_porch_light_2","vt":"str"},{"t":"eq","v":"porch","vt":"str"},{"t":"eq","v":"living_room_main_1","vt":"str"},{"t":"eq","v":"bench_s_light","vt":"str"},{"t":"eq","v":"benchs_left_light","vt":"str"},{"t":"eq","v":"kitchen_bench_left_light","vt":"str"},{"t":"eq","v":"kitchen_bench_right_light","vt":"str"},{"t":"eq","v":"hallway_light","vt":"str"},{"t":"eq","v":"living_lights","vt":"str"},{"t":"eq","v":"living","vt":"str"},{"t":"eq","v":"kitchen_lights","vt":"str"},{"t":"eq","v":"kitchen","vt":"str"},{"t":"eq","v":"living_room_lights","vt":"str"},{"t":"eq","v":"groung_floor_lights","vt":"str"},{"t":"eq","v":"ground_floor_lights","vt":"str"},{"t":"eq","v":"benchlight","vt":"str"},{"t":"eq","v":"tv_porch_light","vt":"str"},{"t":"eq","v":"porch_light","vt":"str"},{"t":"eq","v":"secret_lights","vt":"str"},{"t":"eq","v":"node_clone","vt":"str"},{"t":"eq","v":"kitchen_secret","vt":"str"},{"t":"eq","v":"secret_main","vt":"str"},{"t":"eq","v":"secret_led_main","vt":"str"},{"t":"eq","v":"door_secret","vt":"str"},{"t":"eq","v":"secret_led_two","vt":"str"}],"checkall":"true","repair":false,"outputs":35,"x":103,"y":870,"wires":[["f3a63911.355dd8"],["f3a63911.355dd8"],["f3a63911.355dd8"],["f3a63911.355dd8"],["f3a63911.355dd8"],["f3a63911.355dd8"],["f3a63911.355dd8"],["f3a63911.355dd8"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["3c5516a2.b27a8a"],["a7a51ed1.0508"],["a7a51ed1.0508"],["a7a51ed1.0508"],["a7a51ed1.0508"],["a7a51ed1.0508"],["a7a51ed1.0508"]],"info":"\r\nIn this node we track our slot values. \r\nA path is created for each one.\r\nThis gives us the ability to choose the domain\r\nwe will forward the message to, for further processing.\r\n\r\nReconfigure this node\r\n\r\nIn this node you will have to manually enter your\r\nentities names as found in the developers tools/states,\r\nin your home assistant.\r\nNOTE:you should add them as names without domain, replacing any \" \" \r\nwith \"_\".\r\nThe domain will be added in the next node by linking\r\nthe entity with the desired domain function node.\r\n"},{"id":"f3a63911.355dd8","type":"function","z":"ff77036c.b7acd","name":"\"switch.\" addition","func":"msg.payload.data.entity_id = ('switch.') + msg.payload.data.entity_id;\nreturn msg;","outputs":1,"noerr":0,"x":585,"y":704,"wires":[["dd7f7f6b.4c373","aff2fe9.e2a1a"]],"info":"This function node will add \"switch.\" \nin front of the entity name.\nWire this node with the outputs that will call\nswitch turn_on/off services.\n\nNothing to configure in this node"},{"id":"3c5516a2.b27a8a","type":"function","z":"ff77036c.b7acd","name":"\"group.\" addition","func":"msg.payload.data.entity_id = ('group.') + msg.payload.data.entity_id;\nreturn msg;","outputs":1,"noerr":0,"x":586,"y":766,"wires":[["dd7f7f6b.4c373","bb9a9c58.4b28e"]],"info":"This function node will add \"group.\" \nin front of the entity name.\nWire this node with the outputs that will call\ngroup turn_on/off services.\n\nNothing to configure in this node"},{"id":"a7a51ed1.0508","type":"function","z":"ff77036c.b7acd","name":"\"light.\" addition","func":"msg.payload.data.entity_id = ('light.') + msg.payload.data.entity_id;\nreturn msg;","outputs":1,"noerr":0,"x":578,"y":836,"wires":[["dd7f7f6b.4c373","cf318507.4984b8"]],"info":"This function node will add \"light.\" \nin front of the entity name.\nWire this node with the outputs that will call\nlight turn_on/off services.\n\nNothing to configure in this node"},{"id":"7f6be86e.484648","type":"change","z":"ff77036c.b7acd","name":"Delete values not used in msg1","rules":[{"t":"delete","p":"payload.asrTokens","pt":"msg"},{"t":"delete","p":"payload.slots[1]","pt":"msg"},{"t":"delete","p":"payload.slots[2]","pt":"msg"},{"t":"delete","p":"payload.input","pt":"msg"},{"t":"delete","p":"payload.siteId","pt":"msg"},{"t":"delete","p":"payload.customData","pt":"msg"},{"t":"delete","p":"payload.asrConfidence","pt":"msg"},{"t":"delete","p":"payload.sessionId","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":691,"y":352,"wires":[["cf64a1dc.2cde","6c739a78.f2faa4"]],"info":"Delete values not used in msg1\n\nNothing to configure in this node"},{"id":"dd7f7f6b.4c373","type":"api-call-service","z":"ff77036c.b7acd","name":"turn_on service","server":"4bbac141.a7708","service_domain":"homeassistant","service":"","data":"","mergecontext":"","output_location":"","output_location_type":"none","x":797,"y":605,"wires":[[]],"info":"This node calls the \"turn_on\" service according\nto the values collected \n\nMake sure you have added your server and entities \nare updated.\n\nNothing else to configure in this node"},{"id":"111b6567.0e2b4b","type":"change","z":"ff77036c.b7acd","name":"Delete values not used in msg2","rules":[{"t":"delete","p":"payload.slots[2]","pt":"msg"},{"t":"delete","p":"payload.slots[0]","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":691,"y":406,"wires":[["cf64a1dc.2cde","aa8a045e.8b8868"]],"info":"\nNothing to configure in this node,\n\n\n"},{"id":"a702ceb3.24038","type":"comment","z":"ff77036c.b7acd","name":"THE STEPS","info":" Steps\n1)Track the intent.\n2)Convert the string into a javascript object.\n3)Triple the message.\n4)Set temporary topics for each message and delete extra\n values.\n5)Start value extraction and rebuilt process \n for each message.\n6)Move values in msg.topic.\n7)Make paths for further message processing. \n8)Wire based connection to add \n\"light.\" or \"switch.\" or \"group.\" \n9)Trigger a homeassistant turn_on service.","x":182,"y":1515,"wires":[]},{"id":"83f19088.11975","type":"comment","z":"ff77036c.b7acd","name":"TRIPLE ENTITY TURN_ON/OFF ","info":" A flow that handles dimming commands.\nUp to two entities can be dimmed in a single command.\nIt uses just two slots in snips assistant\n(dim value and entity_id).\nIt will function if the command follows the pattern:\n Fisrt entity and the desired color, followed\nby the second entity and the desired color.\n\n Make sure the entity_id slot in snips assistant\ncontains the names of your home assistant light entities,\nas found in States tab.\n Synonyms will call the actual name of the slot value.\nSo slot value must match. \n\n\n ","x":135,"y":1432,"wires":[]},{"id":"36ed2225.05ef6e","type":"comment","z":"ff77036c.b7acd","name":"Read the comments","info":" Read the comments to help you understand the steps\ninvolved.\n In each node, under Description tab, you will find \na brief node explanation.","x":164,"y":1473,"wires":[]},{"id":"a4554fac.df935","type":"comment","z":"ff77036c.b7acd","name":"THE STEPS","info":" Steps\n1)Track the intent.\n2)Convert the string into a javascript object.\n3)Triple the message.\n4)Set temporary topics for each message and delete extra\n values.\n5)Start value extraction and rebuilt process \n for each message.\n6)Move values in msg.topic.\n7)Make paths for further message processing. \n8)Wire based connection to add \n\"light.\" or \"switch.\" or \"group.\" \n9)Trigger a homeassistant turn_on service.","x":187,"y":123,"wires":[]},{"id":"5fe19c39.725c44","type":"comment","z":"ff77036c.b7acd","name":"TURN_ALL_OFF_EXCEPT","info":" A flow that handles dimming commands.\nUp to two entities can be dimmed in a single command.\nIt uses just two slots in snips assistant\n(dim value and entity_id).\nIt will function if the command follows the pattern:\n Fisrt entity and the desired color, followed\nby the second entity and the desired color.\n\n Make sure the entity_id slot in snips assistant\ncontains the names of your home assistant light entities,\nas found in States tab.\n Synonyms will call the actual name of the slot value.\nSo slot value must match. \n\n\n ","x":130,"y":40,"wires":[]},{"id":"78d6e107.4bc7d","type":"comment","z":"ff77036c.b7acd","name":"Read the comments","info":" Read the comments to help you understand the steps\ninvolved.\n In each node, under Description tab, you will find \na brief node explanation.","x":169,"y":81,"wires":[]},{"id":"c9679e93.b9aff","type":"comment","z":"ff77036c.b7acd","name":"READ ME","info":"The below nodes needs to be re-configured\nRead the Description tab in each ofthe nodes to\nhelp you with your configuration.","x":97,"y":604,"wires":[]},{"id":"6f6361c7.7c46f","type":"comment","z":"ff77036c.b7acd","name":"READ ME","info":"The below nodes needs to be re-configured\nRead the Description tab in each ofthe nodes to\nhelp you with your configuration.","x":127,"y":225,"wires":[]},{"id":"7bacd63e.a200e8","type":"debug","z":"ff77036c.b7acd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":811,"y":513,"wires":[]},{"id":"aff2fe9.e2a1a","type":"debug","z":"ff77036c.b7acd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":759,"y":704,"wires":[]},{"id":"318bbb94.2dd484","type":"debug","z":"ff77036c.b7acd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":420,"y":513,"wires":[]},{"id":"aa8a045e.8b8868","type":"debug","z":"ff77036c.b7acd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":887,"y":406,"wires":[]},{"id":"6c739a78.f2faa4","type":"debug","z":"ff77036c.b7acd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":887,"y":352,"wires":[]},{"id":"cf318507.4984b8","type":"debug","z":"ff77036c.b7acd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":753,"y":835,"wires":[]},{"id":"bb9a9c58.4b28e","type":"debug","z":"ff77036c.b7acd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":759,"y":766,"wires":[]},{"id":"d39274d1.478ca8","type":"comment","z":"ff77036c.b7acd","name":"READ ME","info":"The below nodes needs to be re-configured\nRead the Description tab in each ofthe nodes to\nhelp you with your configuration.","x":736,"y":272,"wires":[]},{"id":"1bf60fd5.acb01","type":"comment","z":"ff77036c.b7acd","name":"READ ME","info":"The below nodes needs to be re-configured\nRead the Description tab in each ofthe nodes to\nhelp you with your configuration.","x":120,"y":486,"wires":[]},{"id":"3cef8672.a39a5a","type":"debug","z":"ff77036c.b7acd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":886,"y":294,"wires":[]},{"id":"164c9163.411d4f","type":"delay","z":"ff77036c.b7acd","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":481,"y":353,"wires":[["7f6be86e.484648"]],"info":"Delay used to let the turn_on services triggered \nafter the turn_off.\n\nYou can adjust the delay if you experience any issue\nwith this flow. (light turned on and off rapidly)"},{"id":"dea1d069.b98eb","type":"delay","z":"ff77036c.b7acd","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":480,"y":406,"wires":[["111b6567.0e2b4b"]],"info":"Delay used to let the turn_on services triggered \nafter the turn_off.\n\nYou can adjust the delay if you experience any issue\nwith this flow. (light turned on and off rapidly)"},{"id":"e92d1794.a4b0d8","type":"mqtt-broker","z":"","name":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"4bbac141.a7708","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]