Refresh z-wave entities with each Google Assistant command

Here’s a Node-Red flow to refresh z-wave entities turned on/off through Google Assistant.

[{"id":"825b0eb990d0eb62","type":"tab","label":"v4-Google","disabled":false,"info":"","env":[]},{"id":"589961cd2bfa09b7","type":"server-events","z":"825b0eb990d0eb62","name":"Command","server":"dddbb284fd154f82","version":1,"event_type":"google_assistant_command","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"},{"property":"payload","propertyType":"msg","value":"$outputData(\"eventData\").entity_id","valueType":"jsonata"},{"property":"command","propertyType":"msg","value":"$outputData(\"eventData\").event.execution[0].command","valueType":"jsonata"}],"x":100,"y":100,"wires":[["42be3bcdd3231409"]]},{"id":"9e337cce8cd226f6","type":"switch","z":"825b0eb990d0eb62","name":"Desired Devices","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"light.","vt":"str"},{"t":"cont","v":"switch.","vt":"str"},{"t":"cont","v":"fan.","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":500,"y":160,"wires":[["bcb00c2faed81c63"],["bcb00c2faed81c63"],["bcb00c2faed81c63"],[]],"info":"Filters to desired devices (ex. only refresh lights, switches, and fans)"},{"id":"a74946e3c8131f38","type":"api-call-service","z":"825b0eb990d0eb62","name":"Refresh Zwave","server":"dddbb284fd154f82","version":5,"debugenabled":false,"domain":"zwave_js","service":"refresh_value","areaId":[],"deviceId":[],"entityId":["{{ payload }}"],"data":"{\"entity_id\":\"{{{payload}}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":940,"y":160,"wires":[[]],"info":"Refreshes the value of a given zwave node"},{"id":"8ee484b40780a06f","type":"switch","z":"825b0eb990d0eb62","name":"Desired Command","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"action.devices.commands.OnOff","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":310,"y":220,"wires":[["9e337cce8cd226f6"]],"info":"Limit processing to voice commands that turn devices on and off"},{"id":"1b06106ca05ae11e","type":"comment","z":"825b0eb990d0eb62","name":"Refresh zwave devices once google assistant on/off is given","info":"","x":260,"y":40,"wires":[]},{"id":"42be3bcdd3231409","type":"split","z":"825b0eb990d0eb62","name":"Parse Entities","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"","x":220,"y":160,"wires":[["8ee484b40780a06f"]],"info":"Voice commands can affect multiple entities.  This node will parse each entity into its own message."},{"id":"bcb00c2faed81c63","type":"delay","z":"825b0eb990d0eb62","name":"Wait for execution","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":730,"y":160,"wires":[["a74946e3c8131f38"]],"info":"This will help prevent early refreshing of the zwave node (i.e. before the goolge command has had time to execute)"},{"id":"dddbb284fd154f82","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

Problem this solves for:
I have a lot of non-z-wave plus devices which typically have delayed or stale states - i.e. you tell Google to turn on a light, the light turns on, but home assistant still says the light is off (either for a few seconds, minutes, or forever). This flow listens for Google Assistant device on/off events, parses the target entity or entities, and refreshes the zwave value for each entity.

Why not just poll?
Polling is expensive on your z-wave network, especially if you have a lot of devices. You should use polling sparingly and only when you are unable to use an event driven method like this one.

Requirements:

  • Home assistant
  • Node red
  • ZwaveJS
  • Google Assistant