Obtaining last Alexa device called using

I can't replicate the issue now :man_shrugging:
I've tried all sorts of commands in varied orders - but it's not happening - it's responding from the Alexa that's spoken to. So not sure what happened before when I posted!
I've got a debug node there so I'll post the code if it does it again!

That's neat - I don't think I update the utterances enough to need it, but i'm going to keep that in the back pocket!

Doesn't seem to be working for me tho :frowning:

[{"id":"5f36f9963b89697a","type":"inject","z":"3e59c366f7b1fc0b","name":"","props":[{"p":"routine","v":"Boost Heating","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":890,"y":80,"wires":[["fa60a0b5b7522ddd"]]},{"id":"fa60a0b5b7522ddd","type":"alexa-remote-other","z":"3e59c366f7b1fc0b","name":"","account":"c494972916da5668","config":{"option":"get","value":{"what":"automationRoutines"}},"x":1090,"y":80,"wires":[["4dd3de929cb75875"]]},{"id":"4dd3de929cb75875","type":"change","z":"3e59c366f7b1fc0b","name":"","rules":[{"t":"set","p":"utterances","pt":"msg","to":"[payload[name = $$.routine].triggers.payload.utterances]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1330,"y":80,"wires":[["e71c2f9c2f2ebbe8","4a4f65662385fd52"]]},{"id":"e71c2f9c2f2ebbe8","type":"alexa-remote-other","z":"3e59c366f7b1fc0b","name":"","account":"c494972916da5668","config":{"option":"get","value":{"what":"activities","count":{"type":"num","value":"1"},"offset":{"type":"num","value":"1"}}},"x":1130,"y":180,"wires":[["25d0720670cef0b9"]]},{"id":"25d0720670cef0b9","type":"change","z":"3e59c366f7b1fc0b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[$$.payload[\"CUSTOMER_TRANSCRIPT\" in $keys($.conversionDetails) and \t    $.description.summary in $$.utterances]][0]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1360,"y":180,"wires":[["73ef6dda5da764f7"]]},{"id":"73ef6dda5da764f7","type":"debug","z":"3e59c366f7b1fc0b","name":"debug 97","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.name","targetType":"msg","statusVal":"","statusType":"auto","x":1540,"y":180,"wires":[]},{"id":"4a4f65662385fd52","type":"debug","z":"3e59c366f7b1fc0b","name":"debug 98","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"utterances","targetType":"msg","statusVal":"","statusType":"auto","x":1540,"y":80,"wires":[]},{"id":"c494972916da5668","type":"alexa-remote-account","name":"Alexa Account","authMethod":"proxy","proxyOwnIp":"192.168.1.125","proxyPort":"3456","cookieFile":"/homeassistant/node-red/alexa-auth.txt","refreshInterval":"3","alexaServiceHost":"alexa.amazon.co.uk","pushDispatchHost":"","amazonPage":"amazon.co.uk","acceptLanguage":"en-UK","onKeywordInLanguage":"on","userAgent":"","usePushConnection":"on","autoInit":"on","autoQueryActivityOnTrigger":"on"}]

My routine is called Boost Heating and has three utterances as described, but the output from the debug nodes is

msg.utterances : array[0]
[ empty ]
msg.payload.name : undefined
undefined

What is the output of the other node routine, show us the object for the Boost Heating routine.

Sadly I can't do anything right now...
I'm getting an error on the Get Activities node saying
"Activity update is running, please try again later."

Been doing this since last night :frowning:

Every other GET action seems to work (so not an auth error), but the activities one gives that error :cry:

Anyone any ideas?
I see a few threads about it e.g. here

EDIT: Looks like it needs a delay. I noticed if I injected manually it was working, but a 1 second wasn't sufficient, so I'm at 2 seconds now and seems to be working

Is there any way to catch that error?

[{"id":"cd1df5a6a38e5dca","type":"switch","z":"c3154991461cf27c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"try again","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":90,"y":180,"wires":[["dcab8263d2e286c4"],["743f018f106f43aa"]]},{"id":"bfa8e1dc9d80025d","type":"alexa-remote-other","z":"c3154991461cf27c","name":"","account":"c494972916da5668","config":{"option":"get","value":{"what":"activities","count":{"type":"num","value":"1"},"offset":{"type":"num","value":"1"}}},"x":290,"y":120,"wires":[["66984a104338f5e3","cd1df5a6a38e5dca"]]},{"id":"dcab8263d2e286c4","type":"delay","z":"c3154991461cf27c","name":"","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":120,"y":100,"wires":[["bfa8e1dc9d80025d"]]},{"id":"c494972916da5668","type":"alexa-remote-account","name":"Alexa Account","authMethod":"proxy","proxyOwnIp":"192.168.1.125","proxyPort":"3456","cookieFile":"/homeassistant/node-red/alexa-auth.txt","refreshInterval":"3","alexaServiceHost":"alexa.amazon.co.uk","pushDispatchHost":"","amazonPage":"amazon.co.uk","acceptLanguage":"en-UK","onKeywordInLanguage":"on","userAgent":"","usePushConnection":"on","autoInit":"on","autoQueryActivityOnTrigger":"on"}]

I thought this (or some variant of it) would do it, but it doesn't seem to output from what I can see

EDIT: Solving my own issues and teaching an old dog new tricks this morning - catch node :slight_smile:

This is giving me a headache now...

For some reason the boost heating node is giving me an error when run through this flow:

HomeAssistantError: not a valid value @ data['recordKey']

But I'm not sending an record key

[{"id":"72f811c8aaa070e7","type":"api-call-service","z":"c3154991461cf27c","name":"Boost Study","server":"3aa13fed.bf745","version":7,"debugenabled":false,"action":"wiser.boost_heating","floorId":[],"areaId":[],"deviceId":[],"entityId":["climate.wiser_study"],"labelId":[],"data":"{\"time_period\":60,\"temperature_delta\":3}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":true,"domain":"wiser","service":"boost_heating","x":910,"y":440,"wires":[[]]},{"id":"8deb60af2c44f704","type":"change","z":"c3154991461cf27c","name":"Study","rules":[{"t":"set","p":"room","pt":"msg","to":"the Study","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":440,"wires":[["bc004ed34be88003","72f811c8aaa070e7"]]},{"id":"7cf0985b4af0b9d9","type":"switch","z":"c3154991461cf27c","name":"","property":"payload.name","propertyType":"msg","rules":[{"t":"eq","v":"Alana's Owl","vt":"str"},{"t":"eq","v":"Bathroom","vt":"str"},{"t":"eq","v":"Bedroom","vt":"str"},{"t":"eq","v":"Fire TV 4k","vt":"str"},{"t":"eq","v":"Playroom","vt":"str"},{"t":"eq","v":"Dining Room","vt":"str"},{"t":"eq","v":"Kitchen Echo Show","vt":"str"},{"t":"eq","v":"Open Plan","vt":"str"},{"t":"eq","v":"TV Echo Dot","vt":"str"},{"t":"eq","v":"Andy's Fire TV Cube","vt":"str"},{"t":"eq","v":"Study","vt":"str"},{"t":"eq","v":"Ethan's Dragon","vt":"str"}],"checkall":"true","repair":false,"outputs":12,"x":370,"y":340,"wires":[["2c26cd92f39c7771"],["1443caeac296fba0"],["26b9fe5adfc9cd59"],["6f5c2aea887495c3"],["6f5c2aea887495c3"],["3d3abc1ad45e3482"],["3d3abc1ad45e3482"],["3d3abc1ad45e3482"],["3d3abc1ad45e3482"],["3d3abc1ad45e3482"],["8deb60af2c44f704"],["cb27e88977a21150"]]},{"id":"743f018f106f43aa","type":"change","z":"c3154991461cf27c","name":"Get Device [multi response]","rules":[{"t":"set","p":"payload","pt":"msg","to":"[\t   $$.payload[\t       \"CUSTOMER_TRANSCRIPT\" in $keys($.conversionDetails) and\t\t    $.description.summary in [\t           \"boost the heating\",\t           \"heating boost\",\t           \"it's cold\"\t       ]\t   ]\t][0]","tot":"jsonata"},{"t":"set","p":"notes","pt":"msg","to":"Getting customer transcript item","tot":"str"},{"t":"set","p":"morenotes","pt":"msg","to":"- 0 first list item -1 last","tot":"str"},{"t":"set","p":"helpthread","pt":"msg","to":"https://discourse.nodered.org/t/obtaining-last-alexa-device-called-using/92267/15","tot":"str"},{"t":"set","p":"NOTE","pt":"msg","to":"use payload.name","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":200,"y":160,"wires":[["7cf0985b4af0b9d9","f12709dec80ef52d"]]},{"id":"bfa8e1dc9d80025d","type":"alexa-remote-other","z":"c3154991461cf27c","name":"Get Activities for Boost","account":"c494972916da5668","config":{"option":"get","value":{"what":"activities","count":{"type":"num","value":"1"},"offset":{"type":"num","value":"1"}}},"x":320,"y":100,"wires":[["66984a104338f5e3","743f018f106f43aa"]]},{"id":"dcab8263d2e286c4","type":"delay","z":"c3154991461cf27c","name":"","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":120,"y":100,"wires":[["bfa8e1dc9d80025d"]]},{"id":"a781aa42cc8ba723","type":"trigger-state","z":"c3154991461cf27c","name":"Alexa Boost Helper","server":"3aa13fed.bf745","version":5,"inputs":0,"outputs":2,"exposeAsEntityConfig":"","entities":{"entity":["input_boolean.alexa_boost_heating_helper"],"substring":[],"regex":[]},"debugEnabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":false,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":110,"y":40,"wires":[["75de21f2b60163b4","f291ab904e293e43","dcab8263d2e286c4"],[]]},{"id":"f291ab904e293e43","type":"api-call-service","z":"c3154991461cf27c","name":"Turn Boost Helper Back Off","server":"3aa13fed.bf745","version":7,"debugenabled":false,"action":"input_boolean.turn_off","floorId":[],"areaId":[],"deviceId":[],"entityId":["input_boolean.alexa_boost_heating_helper"],"labelId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"input_boolean","service":"turn_off","x":400,"y":40,"wires":[[]]},{"id":"c26e51835e35925c","type":"catch","z":"c3154991461cf27c","name":"Activities error","scope":["bfa8e1dc9d80025d"],"uncaught":false,"x":90,"y":440,"wires":[["dcab8263d2e286c4"]]},{"id":"f12709dec80ef52d","type":"debug","z":"c3154991461cf27c","name":"debug 95","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":420,"y":180,"wires":[]},{"id":"dd3daf4e146032ea","type":"inject","z":"c3154991461cf27c","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload.name","v":"Study","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":340,"wires":[["7cf0985b4af0b9d9"]]},{"id":"3aa13fed.bf745","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"c494972916da5668","type":"alexa-remote-account","name":"Alexa Account","authMethod":"proxy","proxyOwnIp":"192.168.1.125","proxyPort":"3456","cookieFile":"/homeassistant/node-red/alexa-auth.txt","refreshInterval":"3","alexaServiceHost":"alexa.amazon.co.uk","pushDispatchHost":"","amazonPage":"amazon.co.uk","acceptLanguage":"en-UK","onKeywordInLanguage":"on","userAgent":"","usePushConnection":"on","autoInit":"on","autoQueryActivityOnTrigger":"on"}]

If I inject directly, the node works fine. If i set the payload to blank string in the clear the payload the node works fine (but then I obviously stop passing the room to the speak node)

Not sure I can help with the HA side. I would probably try to do all this in Node-red without HA. I would need to see the messages feed into and out of the alexa other node.

What are the api call node devices that the flow finally sends messages to?

You can use node-red-contrib-amazon-echo (node) - Node-RED which runs locally (old but still working fine)
Or node-red-contrib-virtual-smart-home (node) - Node-RED which I know others use.

You can make one switch do may things by having the routine set a dim level which you can use in node-red to filter to correct flow.

Again the more info we can see the easier it is to help.

Sorry for slow reply - busy weekend!

I solved it by just sticking a change node and resetting the payload before that call - I suspect something was passing through the flow which was causing issues on the HA side - all good now :slight_smile:

One question I did have -
The error catching node below - it works as expected, but in a scenario where it never finishes for some reason, it's just going to keep looping

[{"id":"a781aa42cc8ba723","type":"trigger-state","z":"c3154991461cf27c","name":"Alexa Boost Helper","server":"3aa13fed.bf745","version":5,"inputs":0,"outputs":2,"exposeAsEntityConfig":"","entities":{"entity":["input_boolean.alexa_boost_heating_helper"],"substring":[],"regex":[]},"debugEnabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":false,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":150,"y":40,"wires":[["75de21f2b60163b4","f291ab904e293e43","dcab8263d2e286c4"],[]]},{"id":"dcab8263d2e286c4","type":"delay","z":"c3154991461cf27c","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":370,"y":100,"wires":[["658e76ffeaf2a9ad","bfa8e1dc9d80025d"]]},{"id":"c26e51835e35925c","type":"catch","z":"c3154991461cf27c","name":"Activities error","scope":["bfa8e1dc9d80025d"],"uncaught":false,"x":90,"y":400,"wires":[["dcab8263d2e286c4"]]},{"id":"bfa8e1dc9d80025d","type":"alexa-remote-other","z":"c3154991461cf27c","name":"Get Activities for Boost","account":"c494972916da5668","config":{"option":"get","value":{"what":"activities","count":{"type":"num","value":"1"},"offset":{"type":"num","value":"1"}}},"x":670,"y":100,"wires":[["66984a104338f5e3","743f018f106f43aa","a0014ef26bbd7c1f"]]},{"id":"3aa13fed.bf745","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"c494972916da5668","type":"alexa-remote-account","name":"Alexa Account","authMethod":"proxy","proxyOwnIp":"192.168.1.125","proxyPort":"3456","cookieFile":"/homeassistant/node-red/alexa-auth.txt","refreshInterval":"3","alexaServiceHost":"alexa.amazon.co.uk","pushDispatchHost":"","amazonPage":"amazon.co.uk","acceptLanguage":"en-UK","onKeywordInLanguage":"on","userAgent":"","usePushConnection":"on","autoInit":"on","autoQueryActivityOnTrigger":"on"}]

Is there some way to give a maximum number of times it should push through (e.g. in my case it's trying every second, but can I make it try every second for 10 seconds and then give up until the initial trigger is hit again?

I did briefly try this with a counter but it got extremely complex extremely quickly and I decided there must be an easier way to do this?!

I thought the error node should have a max that is set to approx 5.
Inspect the msg using a debug set to full message object, I sure there is a count and you can use a switch node to stop the loop.

It does have a count, but it never changes - always shows 1

{"error":{"message":"Activity update is running, please try again later.","source":{"id":"bfa8e1dc9d80025d","type":"alexa-remote-other","name":"Get Activities for Boost","count":1}},"_error":"Error: Activity update is running, please try again later.","_msgid":"bd8bab659b95cb1a"}

Note the copy there was on #8 (it takes roughly 8 attempts for the activity to clear on average) - I stuck my own count in to capture the actual count

Strange the alexa node must not be passing the msg.error when the error is thrown again.

This may work as a workaround, its a bit convoluted, you may come up with something better.
It allows 5 errors then resets.

[{"id":"7088f3fae444777e","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":7740,"wires":[["4db77abc479a2f67"]]},{"id":"4db77abc479a2f67","type":"alexa-remote-routine","z":"d1395164b4eec73e","name":"","account":"c8738129.d902c","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"str","value":"test"},"devices":{"type":"str","value":"yrdy"}}},"x":480,"y":7740,"wires":[["fd4699711916d841"]]},{"id":"5821de128e490719","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"error","pt":"msg","to":"$$.error.*[-1]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":7780,"wires":[["0e3242a913072d5a","4db77abc479a2f67"]]},{"id":"fd4699711916d841","type":"debug","z":"d1395164b4eec73e","name":"debug 2578","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":7740,"wires":[]},{"id":"a5db74cbe181d71f","type":"switch","z":"d1395164b4eec73e","name":"","property":"$count($$.error.*)","propertyType":"jsonata","rules":[{"t":"lt","v":"5","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":550,"y":7820,"wires":[["5821de128e490719","0e3242a913072d5a"],["5790eedc7b966278"]]},{"id":"0e3242a913072d5a","type":"debug","z":"d1395164b4eec73e","name":"debug 2579","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":7900,"wires":[]},{"id":"99d8e530c864efbc","type":"join","z":"d1395164b4eec73e","name":"","mode":"custom","build":"object","property":"error","propertyType":"msg","key":"_msgid","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":410,"y":7820,"wires":[["a5db74cbe181d71f","0e3242a913072d5a"]]},{"id":"5790eedc7b966278","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":7820,"wires":[["99d8e530c864efbc"]]},{"id":"bbdeb79da2edfc14","type":"delay","z":"d1395164b4eec73e","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":260,"y":7820,"wires":[["99d8e530c864efbc"]]},{"id":"84531fc0f7863590","type":"catch","z":"d1395164b4eec73e","name":"","scope":["4db77abc479a2f67"],"uncaught":false,"x":130,"y":7820,"wires":[["bbdeb79da2edfc14"]]},{"id":"c8738129.d902c","type":"alexa-remote-account","name":"alexa remote 2","authMethod":"proxy","proxyOwnIp":"localhost","proxyPort":"3456","cookieFile":"/data/data/com.termux/files/home/.node-red/.alexa.cookie","refreshInterval":"14","alexaServiceHost":"layla.amazon.co.uk","pushDispatchHost":"","amazonPage":"amazon.co.uk","acceptLanguage":"en-GB","onKeywordInLanguage":"","userAgent":"","usePushConnection":"on","autoInit":"off","autoQueryActivityOnTrigger":"off"}]
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.