Dim_Hass_entities

Dim_Hass_entities

Usage

This flow supports the Home Assistant Lights Control and Home Assistant via Node-Red app. in Snips app store.

It is used to control the brightness of light/group of light entities in homeassistant.

When the command is given under a certain rule, we can control color changes into two entities in a single command.

It handles the intent produced by Snips.AI assistant, it extracts the needed values and triggers a homeassistant call service (or a mqtt publish message).

https://www.youtube.com/watch?v=kpdakdll3Ac

Requirements

Home Assistant with some light 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.

Snips.AI

  • Add the app "Home Assistant via Node-Red" in your assistant.

  • Edit the slot Rgbentity

In this slot enter the names of the light 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 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:
  dimentities:
    speech: 
      type: plain
      text: '{{ rgbentity  }} dimmed to {{ percentage | round }} percent.  '
 

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: ' ')

MQTT TOPICdebugyamlSET TEMPORARY msg.topicdebugDATA MOVEdebug"group." EXCEPTIONS"light." ADDITIONREPLACE " " , "_"FINAL RECONSTRUCTION STAGEIn this node we are finally calling a homeassistant sevice, with the two altered messages we extracted from the intent.DUPLICATING THE INTENT MESSAGEDUPLICATING THE INTENT MESSAGESETTING msg.topic TO "1"SETTING msg.topic TO "2"debugdebugDIM HIGH LIMIT FOR 1st ENTITYdebugdebugDIM HIGH LIMIT FOR 2ndt ENTITYdebugdebugdebugdebugREADMEREADMEELAMINATING PATHDELETE EXTRA MESSAGEdebugdebugTHE STEPSDUAL ENTITY DIM CONTROLRead the comments
Flow 1
[{"id":"65d49062.57b72","type":"tab","label":"DIM_entity","disabled":false,"info":"Dim one or two light entities.\nNote: in odrer for this flow to function \nyou should keep in mind the command should follow \nthe rule: 1st entity followed by the dim value\nthen the 2nd entity followed by the desired dim value.\nThe current flow is not capable of handling\na different order.\n\n\n This flow is made for users that are running\nHome Assistant and use Node-Red and Snips.AI as\nadd-ons.\n It can be easily switched for use as a flow\n on a satellite device that runs snips and node red \n and publish mqtt messages instead of triggering a \nhomeassistant turn_service. \n"},{"id":"f9b9c9e4.2326b8","type":"mqtt in","z":"65d49062.57b72","name":"MQTT TOPIC","topic":"hermes/intent/nik_poz:dimentities","qos":"2","datatype":"auto","broker":"e92d1794.a4b0d8","x":101,"y":177,"wires":[["810be6d4.dc2ea8"]],"info":"This node needs to be reconfigured\n\n1)Add your server.\n2)Repalce \"nik_poz:Rgbandentity\" in the topic area, \nin the Properties tab.\n\n\nTip:\n I found the internal one(127.0.0.1),\nworking better for me.\n Try listening on both of your servers \n and see what works best for you.\n \nNote:\nMake sure you have added your server credentials."},{"id":"129cc7ea.9d8968","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":494,"y":178,"wires":[]},{"id":"810be6d4.dc2ea8","type":"yaml","z":"65d49062.57b72","property":"payload","name":"","x":378,"y":177,"wires":[["129cc7ea.9d8968","4da6b7fb.74c6a8","5ead9885.0ae338"]]},{"id":"7d116fdd.8efca","type":"change","z":"65d49062.57b72","name":"SET TEMPORARY msg.topic","rules":[{"t":"set","p":"topic","pt":"msg","to":"{    \"domain\": \"homeassistant\",    \"service\": \"turn_on\",    \"data\": {        \"entity_id\": \"group.secret_lights\",  \"brightness\": 10    }}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":177,"y":456,"wires":[["c3df467f.c78378","3d12d508.7c350a"]],"info":"In this node we are setting up on msg.topic the\nformat that we will use to trigger a \nhomeassistant light.turn_on service.\n All content of the msg.topic will become \n msg.payload later on in the process.\n\n\n"},{"id":"c3df467f.c78378","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":383,"y":460,"wires":[]},{"id":"3d12d508.7c350a","type":"change","z":"65d49062.57b72","name":"DATA MOVE","rules":[{"t":"move","p":"payload.slots[1].value.value","pt":"msg","to":"topic.data.brightness","tot":"msg"},{"t":"move","p":"payload.slots[0].value.value","pt":"msg","to":"topic.data.entity_id","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":142,"y":560,"wires":[["dd6ea047.692a","ccd0e76f.7ddb78"]],"info":"In this node the converted values are moved in the\ncorresponding fields in the format we created earlier in the \nmsg.topic.\n\nNothing to configure."},{"id":"dd6ea047.692a","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":278,"y":561,"wires":[]},{"id":"a61b2c8d.28385","type":"change","z":"65d49062.57b72","name":"\"group.\"  EXCEPTIONS","rules":[{"t":"change","p":"topic.data.entity_id","pt":"msg","from":"light.secret lights","fromt":"str","to":"group.secret lights","tot":"str"},{"t":"change","p":"topic.data.entity_id","pt":"msg","from":"light.tv secret lights","fromt":"str","to":"group.tv secret lights","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":824,"y":563,"wires":[["161170fa.9f0b1f","cff5d708.a4aa08"]],"info":" In this node you will have to manually insert all \nlight entities that are grouped together\nas found in your homeassistant group.yaml.\n\n\n It is used to track group entities and change into \n\"group.\"  the \"light.\" addition they gained in the \nprevious node \nUse the given example as your guide to comfigure \nthis node. \n\nExample:\nIn this flow, there are two groups off dimmable\nlights. \"secret lights\" and \"tv secret lights\".\nWe replace the \"light.\" with \"group.\",\nby tracking their names.\nAdd the replacement for your group of light entities.\n\n\n\nNote:\n This node will look in the entity_id used in your \nsnips assistant and detect names that we like to function\nas light groups.\n Be sure that the names of the group entities you use\nmatch the names used in Home Assistant as well.\n Editing snips entity_id slot is also required to match\nthe exact spelling of the home assistant configuration.\n\n"},{"id":"ccd0e76f.7ddb78","type":"function","z":"65d49062.57b72","name":"\"light.\" ADDITION","func":"msg.topic.data.entity_id = ('light.') + msg.topic.data.entity_id;\nreturn msg;","outputs":1,"noerr":0,"x":455,"y":561,"wires":[["a61b2c8d.28385","a58ce75b.260318"]],"info":"In this node we give to the entity the approriate\n\"light.\" addition that it needs.\n\nNothing to configure."},{"id":"161170fa.9f0b1f","type":"change","z":"65d49062.57b72","name":"REPLACE   \"  \" , \"_\"","rules":[{"t":"change","p":"topic.data.entity_id","pt":"msg","from":" ","fromt":"str","to":"_","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":145,"y":742,"wires":[["e1f83076.919cd","f76eef3a.3865d"]],"info":"In this node the \" \"  contained in the entity's name is\nreplaced by \"_\".\n\nUsually nothing to add in this configuration."},{"id":"e1f83076.919cd","type":"change","z":"65d49062.57b72","name":"FINAL RECONSTRUCTION STAGE","rules":[{"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":537,"y":743,"wires":[["3fef620e.7b11ae","40334b13.27b394"]],"info":"Final stage.\nSetting msg.payload with all the data we collected\ninto the msg.topic.\n\nNothing to configure.\n"},{"id":"513fe94e.5c6428","type":"api-call-service","z":"65d49062.57b72","name":"","server":"4bbac141.a7708","service_domain":"homeassistant","service":"","data":"{\"entity_id\":\"nik_poz\"}","mergecontext":"","output_location":"","output_location_type":"none","x":252,"y":978,"wires":[[]],"info":"In this node we are finally \ncalling a homeassistant sevice, with the two altered\nmessages we extracted from the intent.\n"},{"id":"4da6b7fb.74c6a8","type":"switch","z":"65d49062.57b72","name":"DUPLICATING THE INTENT MESSAGE","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":171,"y":291,"wires":[["67a3775b.c51b38","5ff3d0a7.7b743"]],"info":"In this node we are duplicating intent message,\nIn the second message we will add the values\nfor the second entity we want to control,if any.\nElse, we will delete the message later on, \ntracking it by a \"mistake\" we will do by intention.\n\nNothing to configure in this node."},{"id":"5ead9885.0ae338","type":"switch","z":"65d49062.57b72","name":"DUPLICATING THE INTENT MESSAGE","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":165,"y":337,"wires":[["6b3d15aa.86832c","e6aa717f.21782"]],"info":"In this node we are duplicating intent message,\nIn the second message we will add the values\nfor the second entity we want to control,if any.\nElse, we will delete the message later on, \ntracking it by a \"mistake\" we will do by intention.\n\nNothing to configure in this node."},{"id":"12539003.9f1a4","type":"change","z":"65d49062.57b72","name":"SETTING msg.topic TO \"1\"","rules":[{"t":"set","p":"topic","pt":"msg","to":"1","tot":"str"},{"t":"delete","p":"payload.sessionId","pt":"msg"},{"t":"delete","p":"payload.asrTokens","pt":"msg"},{"t":"delete","p":"payload.slots[2]","pt":"msg"},{"t":"delete","p":"payload.slots[3]","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":949,"y":297,"wires":[["7d116fdd.8efca"]],"info":"In this node we create seperate names for the messages\nin order to delete the extra values and leave each of\nmessages just with the values we care for.\n\nNothing to configure\n\nNote:\n After this process the messages should both contain\nno more data that the data needed. From now on the\nmessages will follow the same path for extracting\nthe data,so all messages should look similar. \n Bare that in mind if you find yourself \ninterested in addind a third message in this flow.\n\n\n"},{"id":"d866dd29.5980c","type":"change","z":"65d49062.57b72","name":"SETTING msg.topic TO \"2\"","rules":[{"t":"set","p":"topic","pt":"msg","to":"2","tot":"str"},{"t":"delete","p":"payload.sessionId","pt":"msg"},{"t":"delete","p":"payload.asrTokens","pt":"msg"},{"t":"delete","p":"payload.slots[1]","pt":"msg"},{"t":"delete","p":"payload.slots[0]","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":951,"y":348,"wires":[["7d116fdd.8efca"]],"info":"In this node we create seperate names for the messages\nin order to delete the extra values and leave each of\nmessages just with the values we care for.\n\nNothing to configure\n\nNote:\n After this process the messages should both contain\nno more data that the data needed. From now on the\nmessages will follow the same path for extracting\nthe data,so all messages should look similar. \n Bare that in mind if you find yourself \nintrested of addind a third message in this flow.\n\n\n"},{"id":"67a3775b.c51b38","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":345,"y":292,"wires":[]},{"id":"6b3d15aa.86832c","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":342,"y":336,"wires":[]},{"id":"5ff3d0a7.7b743","type":"switch","z":"65d49062.57b72","name":"DIM HIGH LIMIT FOR 1st ENTITY","property":"payload.slots[1].value.value","propertyType":"msg","rules":[{"t":"gt","v":"50","vt":"num"},{"t":"lte","v":"50","vt":"num"}],"checkall":"true","repair":true,"outputs":2,"x":553,"y":291,"wires":[[],["66c12ea4.b9228","12539003.9f1a4"]],"info":"In this node we can set a high value limit \nfor the entities.\nIt can be set to different prices for each message.\nIf the price is overidden no msg will be sent.\n\nMaximum price to use 255."},{"id":"66c12ea4.b9228","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":756,"y":297,"wires":[]},{"id":"3fef620e.7b11ae","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":759,"y":744,"wires":[]},{"id":"e6aa717f.21782","type":"switch","z":"65d49062.57b72","name":"DIM HIGH LIMIT FOR 2ndt ENTITY","property":"payload.slots[3].value.value","propertyType":"msg","rules":[{"t":"gt","v":"60","vt":"num"},{"t":"lte","v":"60","vt":"num"}],"checkall":"true","repair":true,"outputs":2,"x":551,"y":336,"wires":[[],["d866dd29.5980c","ee435a6e.1e07a8"]],"info":"In this node we can set a high value limit \nfor the entities.\nIt can be set to different prices for each message.\nIf the price is overidden no msg will be sent.\n\nMaximum price to use 255."},{"id":"ee435a6e.1e07a8","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":756,"y":344,"wires":[]},{"id":"a58ce75b.260318","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":625,"y":561,"wires":[]},{"id":"cff5d708.a4aa08","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":999,"y":565,"wires":[]},{"id":"f76eef3a.3865d","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":305,"y":742,"wires":[]},{"id":"62930cb4.adbed4","type":"comment","z":"65d49062.57b72","name":"README","info":"In this node you will have to manually insert all \nlight entities that are grouped together\nas found in your homeassistant group.yaml\n\nIt is used to add \"group.\" instead of the\n\"light.\" addition, added in the previous node.\n\nIn this flow, there are two groups off dimmable\nlights. \"secret lights\" and \"tv secret lights\".\nWe replace the \"light.\" with \"group.\",\nby tracking their names.\n\nReconfigure yours to match the names of your light\ngroups as found in your group.yaml.","x":826,"y":544,"wires":[]},{"id":"ab93d07d.315e5","type":"comment","z":"65d49062.57b72","name":"README","info":"The node below can be adjusted","x":573,"y":274,"wires":[]},{"id":"40334b13.27b394","type":"switch","z":"65d49062.57b72","name":"ELAMINATING PATH","property":"payload.data.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"light.group.secret_lights","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":174,"y":864,"wires":[["e7b4a618.40dcb8"],["52e2adeb.774384","513fe94e.5c6428"]],"info":"This node is used to distinguse whether the incoming\nmessages are both true by tracking the none altered\nvalue in the entity_id ,that through the message\nreconstruction process has let unedited and became\n\"light.light.kitchen_secret\" that cannot be called\nas a service. We will use that mistake to track if both \nmessages are altered with proper values.\nA path is created for the elemination of the \nsecond message we created in the begining, if it hasn't\nbeing edited through this process.\n\nNothing to configure."},{"id":"e7b4a618.40dcb8","type":"change","z":"65d49062.57b72","name":"DELETE EXTRA MESSAGE","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":623,"y":843,"wires":[["b53b4c01.24ff4"]],"info":"In this node is passed the unedited extra message \nand it is deleted.\n\nNothing to configure."},{"id":"52e2adeb.774384","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":374,"y":871,"wires":[]},{"id":"b53b4c01.24ff4","type":"debug","z":"65d49062.57b72","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":837,"y":844,"wires":[]},{"id":"6b6b7f19.fa6ee","type":"comment","z":"65d49062.57b72","name":"THE STEPS","info":"    Steps\n1)Track the intent.\n2)Convert the string into a javascript object.\n3)Duplicate the message.\n4)Set temporary topics for each message and delete extra\n  values.\n5)Start rebuilt process in msg.topic for each message.\n6)Convert the name of the colors to rgb values.\n7)Move values in msg.topic.\n8)Add the \"light.\" to the entity_id value.\n9)Change the \"light.\" to \"group.\" in order  \n  control a group of light entities.\n10)Replace the \" \" with \"_\" .\n11)Move to msg.payload the collected values.\n12)Delete the second message if only one entity's\n  color is commanded to changed.\n13)Trigger a homeassistant turn_on service.","x":189,"y":103,"wires":[]},{"id":"6cab8966.8aff08","type":"comment","z":"65d49062.57b72","name":"DUAL ENTITY DIM CONTROL","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":142,"y":20,"wires":[]},{"id":"9413dd28.123d6","type":"comment","z":"65d49062.57b72","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":171,"y":61,"wires":[]},{"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}]

Flow Info

Created 6 years, 5 months ago
Updated 6 years, 3 months ago
Rating: not yet rated

Owner

Actions

Node Types

Core
  • change (x8)
  • comment (x5)
  • debug (x13)
  • function (x1)
  • mqtt in (x1)
  • mqtt-broker (x1)
  • switch (x5)
  • yaml (x1)
Other

Tags

  • #homeassistant
  • #HomeAssistant
  • #snips.ai
  • #Snips.AI
  • #Snips
  • #snips
  • #Snips.Ai
  • #Snips.ai
  • #hass
  • #Dim
  • #Brightness
  • #lightcontrol
  • #Dim_entities
  • dimentities
  • #dimentity
  • #dim_entity
  • #dim_entities
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option