gsbrewer wrote:Has anyone ever get Alexa to display the proper state of a simple device (like a light) after issuing the command for on/off? Im using Node-Red SmartHome version, and all the devices are working well, but the Alexa App and the echo show never update properly. I turned off auto acknowledge and Im acknowledging in an "Alexa smart home v3 rest" node (and Alexa is happy with that) but I assume there is something that I need to do in the msg.. I just don't what it is. Any help is appreciated.
Yes, the trick is the Function node between indigo and the Alexa device (Which it looks like you got figured out). That puts the payload into a format that Alexa understands. I typically don't use an Alexa device to see if something is on or not.... so the only thing I have that updates the Alexa states is motion. I specifically chose motion so I could initiate a routine. It's not a motion sensor that triggers, it's a HTTP Put command in an Action from Indigo... so it can be whatever. Then on the Alexa side, I can create a routine based on motion to do whatever.
Motion Function for Alexa:
- Code: Select all
[{"id":"4c09d0d7.1dda98","type":"function","z":"a4cd1693.e6598","name":"Translate for Alexa Motion","func":"// Motion State\nif (msg.payload == \"ON\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"DETECTED\" } }, \"acknowledge\" : true };\n}\nelse if (msg.payload == \"OFF\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"NOT_DETECTED\" } }, \"acknowledge\" : true };\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":310,"y":580,"wires":[[]]}]
- Screen Shot 2021-01-30 at 8.43.56 PM.png (95.03 KiB) Viewed 5591 times
Or here is the whole flow that I use:
- Code: Select all
[{"id":"a4cd1693.e6598","type":"tab","label":"Routine Relays","disabled":false,"info":""},{"id":"4470dc4.1ffe324","type":"debug","z":"a4cd1693.e6598","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":360,"y":160,"wires":[]},{"id":"aed4cd13.bf9f68","type":"http in","z":"a4cd1693.e6598","name":"Relay","url":"/Relay","method":"get","upload":false,"swaggerDoc":"","x":70,"y":280,"wires":[["4470dc4.1ffe324","ccd8c2a7.6e61b8","93ba7b6c.51a7c8"]]},{"id":"ccd8c2a7.6e61b8","type":"http response","z":"a4cd1693.e6598","name":"","statusCode":"","headers":{},"x":390,"y":380,"wires":[]},{"id":"93ba7b6c.51a7c8","type":"json","z":"a4cd1693.e6598","name":"","property":"payload","action":"","pretty":false,"x":250,"y":280,"wires":[["660a605a.0cd18"]]},{"id":"660a605a.0cd18","type":"switch","z":"a4cd1693.e6598","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"{\"one\":\"on\"}","vt":"str"},{"t":"eq","v":"{\"one\":\"off\"}","vt":"str"},{"t":"eq","v":"{\"two\":\"on\"}","vt":"str"},{"t":"eq","v":"{\"two\":\"off\"}","vt":"str"},{"t":"eq","v":"{\"three\":\"on\"}","vt":"str"},{"t":"eq","v":"{\"three\":\"off\"}","vt":"str"},{"t":"eq","v":"{\"four\":\"on\"}","vt":"str"},{"t":"eq","v":"{\"four\":\"off\"}","vt":"str"},{"t":"eq","v":"{\"five\":\"on\"}","vt":"str"},{"t":"eq","v":"{\"five\":\"off\"}","vt":"str"}],"checkall":"true","repair":false,"outputs":10,"x":390,"y":280,"wires":[["ce7d1a4b.191cc"],["f5586c5c.85c908"],["ea842d36.e1ad68"],["90fcb45d.c6d298"],["54d36ba8.735cfc"],["f83c682.6994b18"],["3bbb0c22.abda4c"],["9378792c.55c678"],["9df8d79c.1ee2e8"],["bd9313e5.39cdc8"]]},{"id":"ce7d1a4b.191cc","type":"change","z":"a4cd1693.e6598","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":60,"wires":[["aea40ccc.c3a1a"]]},{"id":"f5586c5c.85c908","type":"change","z":"a4cd1693.e6598","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":100,"wires":[["aea40ccc.c3a1a"]]},{"id":"aea40ccc.c3a1a","type":"function","z":"a4cd1693.e6598","name":"Translate for Alexa Motion","func":"// Motion State\nif (msg.payload == \"ON\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"DETECTED\" } }, \"acknowledge\" : true };\n}\nelse if (msg.payload == \"OFF\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"NOT_DETECTED\" } }, \"acknowledge\" : true };\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":80,"wires":[["e8f6cc20.d4f878","a1699d50.d555b8"]]},{"id":"e8f6cc20.d4f878","type":"debug","z":"a4cd1693.e6598","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1000,"y":100,"wires":[]},{"id":"a1699d50.d555b8","type":"alexa-smart-home-v3-state","z":"a4cd1693.e6598","conf":"5da0db12.ace44c","device":"13105","name":"Relay_One","x":990,"y":60,"wires":[]},{"id":"ea842d36.e1ad68","type":"change","z":"a4cd1693.e6598","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":160,"wires":[["d432350.c439248"]]},{"id":"90fcb45d.c6d298","type":"change","z":"a4cd1693.e6598","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":200,"wires":[["d432350.c439248"]]},{"id":"d432350.c439248","type":"function","z":"a4cd1693.e6598","name":"Translate for Alexa Motion","func":"// Motion State\nif (msg.payload == \"ON\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"DETECTED\" } }, \"acknowledge\" : true };\n}\nelse if (msg.payload == \"OFF\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"NOT_DETECTED\" } }, \"acknowledge\" : true };\n}","outputs":1,"noerr":0,"x":770,"y":180,"wires":[["c8d2edbd.b698e8","6a62e72.e83b018"]]},{"id":"c8d2edbd.b698e8","type":"debug","z":"a4cd1693.e6598","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1000,"y":200,"wires":[]},{"id":"6a62e72.e83b018","type":"alexa-smart-home-v3-state","z":"a4cd1693.e6598","conf":"5da0db12.ace44c","device":"13106","name":"Relay_Two","x":990,"y":160,"wires":[]},{"id":"54d36ba8.735cfc","type":"change","z":"a4cd1693.e6598","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":260,"wires":[["af8b4242.b80278"]]},{"id":"f83c682.6994b18","type":"change","z":"a4cd1693.e6598","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":300,"wires":[["af8b4242.b80278"]]},{"id":"af8b4242.b80278","type":"function","z":"a4cd1693.e6598","name":"Translate for Alexa Motion","func":"// Motion State\nif (msg.payload == \"ON\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"DETECTED\" } }, \"acknowledge\" : true };\n}\nelse if (msg.payload == \"OFF\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"NOT_DETECTED\" } }, \"acknowledge\" : true };\n}","outputs":1,"noerr":0,"x":770,"y":280,"wires":[["60b61cc6.195084","fad6976b.23bfc8"]]},{"id":"60b61cc6.195084","type":"debug","z":"a4cd1693.e6598","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1000,"y":300,"wires":[]},{"id":"fad6976b.23bfc8","type":"alexa-smart-home-v3-state","z":"a4cd1693.e6598","conf":"5da0db12.ace44c","device":"13107","name":"Relay_Three","x":990,"y":260,"wires":[]},{"id":"3bbb0c22.abda4c","type":"change","z":"a4cd1693.e6598","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":360,"wires":[["b34de8a1.65444"]]},{"id":"9378792c.55c678","type":"change","z":"a4cd1693.e6598","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":400,"wires":[["b34de8a1.65444"]]},{"id":"b34de8a1.65444","type":"function","z":"a4cd1693.e6598","name":"Translate for Alexa Motion","func":"// Motion State\nif (msg.payload == \"ON\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"DETECTED\" } }, \"acknowledge\" : true };\n}\nelse if (msg.payload == \"OFF\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"NOT_DETECTED\" } }, \"acknowledge\" : true };\n}","outputs":1,"noerr":0,"x":770,"y":380,"wires":[["3cfe7ffc.d366","da14bdd8.1d419"]]},{"id":"3cfe7ffc.d366","type":"debug","z":"a4cd1693.e6598","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1000,"y":400,"wires":[]},{"id":"da14bdd8.1d419","type":"alexa-smart-home-v3-state","z":"a4cd1693.e6598","conf":"5da0db12.ace44c","device":"13108","name":"Relay_Four","x":990,"y":360,"wires":[]},{"id":"9df8d79c.1ee2e8","type":"change","z":"a4cd1693.e6598","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":460,"wires":[["cdfdd755.2201b8"]]},{"id":"bd9313e5.39cdc8","type":"change","z":"a4cd1693.e6598","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":500,"wires":[["cdfdd755.2201b8"]]},{"id":"cdfdd755.2201b8","type":"function","z":"a4cd1693.e6598","name":"Translate for Alexa Motion","func":"// Motion State\nif (msg.payload == \"ON\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"DETECTED\" } }, \"acknowledge\" : true };\n}\nelse if (msg.payload == \"OFF\") {\n return { \"payload\" : { \"state\" : { \"motion\" : \"NOT_DETECTED\" } }, \"acknowledge\" : true };\n}","outputs":1,"noerr":0,"x":770,"y":480,"wires":[["27c9c11.92ecd3e","a07c90a9.340f18"]]},{"id":"27c9c11.92ecd3e","type":"debug","z":"a4cd1693.e6598","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1000,"y":500,"wires":[]},{"id":"a07c90a9.340f18","type":"alexa-smart-home-v3-state","z":"a4cd1693.e6598","conf":"5da0db12.ace44c","device":"13109","name":"Relay_Five","x":990,"y":460,"wires":[]},{"id":"5da0db12.ace44c","type":"alexa-smart-home-v3-conf","username":"yourUserName","mqttserver":"mq-red.cb-net.co.uk","webapiurl":"red.cb-net.co.uk","contextName":"memory"}]