hardillb / node-red-alexa-home-skill-web

Apache License 2.0
45 stars 29 forks source link

Devices not responding to requests #45

Closed aleonnet closed 6 years ago

aleonnet commented 6 years ago

Hi @hardillb, very good job!

I setup the service on my node-red hub just today and On/Off commands works great and as well as setting up temperature. However, Alexa is return the message "The device x is not responding" when I question current and target temperatures. The msg.command (GetTemperatureReadingRequest and GetTargetTemperatureRequest) arrived as expected via Alexa Home node and I also made sure to sent back the msg.extra and msg.payload(true) via Alexa Home Resp node using the code you suggest in https://alexa-node-red.bm.hardill.me.uk/docs.

What I may be doing wrong?

Thank you. Regards, Alessandro

hardillb commented 6 years ago

Please put a sample of the full message you are sending to the response node

aleonnet commented 6 years ago

The message that I receive from Alexa Home after requesting the target temperature: object topic: "" name: "Living room temperature" _messageId: "c720ce8c-54bf-4229-9cd6-9cca95efbf57" _applianceId: "17117" _confId: "1e4de5f.63b119a" command: "GetTargetTemperatureRequest" extraInfo: object empty _msgid: "faa130b5.a233a"

The full message I sent back using Alexa Home Resp: object topic: "" name: "Living room temperature" _messageId: "c720ce8c-54bf-4229-9cd6-9cca95efbf57" _applianceId: "17117" _confId: "1e4de5f.63b119a" command: "GetTargetTemperatureRequest" extraInfo: object empty _msgid: "faa130b5.a233a" extra: object targetTemperature: object value: 25 temperatureMode: object value: "AUTO" payload: true

aleonnet commented 6 years ago

The same for current temperature request for Living room temperature: object topic: "" name: "Living room temperature" _messageId: "0d052d13-bd06-4ad4-b168-c47c4783a27e" _applianceId: "17117" _confId: "1e4de5f.63b119a" command: "GetTemperatureReadingRequest" extraInfo: object empty _msgid: "6357b28e.9f415c"

Message sent back using Alexa Home Resp: object topic: "" name: "Living room temperature" _messageId: "0d052d13-bd06-4ad4-b168-c47c4783a27e" _applianceId: "17117" _confId: "1e4de5f.63b119a" command: "GetTemperatureReadingRequest" extraInfo: object temperatureReading: object value: 21.11 applianceResponseTimestamp: "2018-02-13T23:49:09.313Z" _msgid: "6357b28e.9f415c" payload: true

hardillb commented 6 years ago

Please post the actual json, not the content of the debug sidebar so I can see properly how it's arranged. You can get the debug node to output to the console if needed

aleonnet commented 6 years ago

Apologies, I thought you were requesting the full message object.

I'm testing it with the following code/json in a function node:

if (msg.command == "GetTemperatureReadingRequest") {
  msg.extra = {
      temperatureReading: {
          value: 21.11
      },
      applianceResponseTimestamp: new Date().toISOString()
  };
  msg.payload = true;
} else if (msg.command == "GetTargetTemperatureRequest") {
  msg.extra = {
      targetTemperature: {
          value: 25.0
      },
      temperatureMode: {
          value: "AUTO"
      }
  };
  msg.payload = true;
}
return msg; 
aleonnet commented 6 years ago

From the console

{
   topic: '',
   name: 'Living room temperature',
   _messageId: '5eb13a10-f658-466c-96f3-6d8ccfa44448',
   _applianceId: '17117',
   _confId: '1e4de5f.63b119a',
   command: 'GetTemperatureReadingRequest',
   extraInfo: {},
   _msgid: 'fd866467.3dd108'
}

14 Feb 12:20:40 - [info] [debug:a3f23b93.40dda]
{
  topic: '',
  name: 'Living room temperature',
  _messageId: '5eb13a10-f658-466c-96f3-6d8ccfa44448',
  _applianceId: '17117',
  _confId: '1e4de5f.63b119a',
  command: 'GetTemperatureReadingRequest',
  extraInfo: {},
  _msgid: 'fd866467.3dd108',
  extra:
  {
    temperatureReading: {
      value: 21.11
    },
    applianceResponseTimestamp: '2018-02-14T14:20:40.428Z' 
  },
  payload: true
}
hardillb commented 6 years ago

For GetTargetTemperatureRequest the function should look like this:

if (msg.command === 'GetTargetTemperatureRequest') {
    msg.extra = {
        "targetTemperature": {
            "value": 25
        },
        "applianceResponseTimestamp": new Date().toISOString(),
        "temperatureMode": {
            "value": "AUTO"
        }
    };
    msg.payload = true;
}
return msg;

It looks like you are missing the applianceResponseTimestamp

sample request/response

14 Feb 19:27:18 - [info] [debug:aaae8cd6.e2e59] 
{
    topic: 'test',
    name: 'Bedroom Heater',
    _messageId: '293fb861-be3b-408a-b1b5-5549cd064d80',
    _applianceId: '12882',
    _confId: 'cc670790.9f0eb8',
    command: 'GetTargetTemperatureRequest',
    extraInfo: {},
    _msgid: '1bb30c9c.341773' 
}
14 Feb 19:27:18 - [info] [debug:16991ac0.123575] 
{
    topic: 'test',
    name: 'Bedroom Heater',
    _messageId: '293fb861-be3b-408a-b1b5-5549cd064d80',
    _applianceId: '12882',
    _confId: 'cc670790.9f0eb8',
    command: 'GetTargetTemperatureRequest',
    extraInfo: {},
    _msgid: '1bb30c9c.341773',
    extra: 
    {
        targetTemperature: {
            value: 25
       },
       applianceResponseTimestamp: '2018-02-14T19:27:18.331Z',
       temperatureMode: {
          value: 'AUTO'
       }
    },
    payload: true
}

For the GetTemperatureReadingRequest the function should be:

if (msg.command == 'GetTemperatureReadingRequest') {
    msg.extra = {
        "temperatureReading": {
            "value": 21.5
        },
        "applianceResponseTimestamp": new Date().toISOString()
    };
    msg.payload = true;
}
return msg;

Sample input/output

14 Feb 19:30:11 - [info] [debug:aaae8cd6.e2e59] 
{
    topic: 'test',
    name: 'Bedroom Heater',
    _messageId: 'd8fcb46f-fc46-46e6-9474-8960f8a71952',
    _applianceId: '12882',
    _confId: 'cc670790.9f0eb8',
    command: 'GetTemperatureReadingRequest',
    extraInfo: {},
    _msgid: '7efe5163.27848'
}
14 Feb 19:30:11 - [info] [debug:e26c7ffc.fc16d] 
{
    topic: 'test',
    name: 'Bedroom Heater',
    _messageId: 'd8fcb46f-fc46-46e6-9474-8960f8a71952',
    _applianceId: '12882',
    _confId: 'cc670790.9f0eb8',
    command: 'GetTemperatureReadingRequest',
    extraInfo: {},
    _msgid: '7efe5163.27848',
    extra: {
        temperatureReading: {
            value: 21.5
        },
        applianceResponseTimestamp: '2018-02-14T19:30:11.742Z'
    },
    payload: true
}
aleonnet commented 6 years ago

The issue does not appear to be related to the syntax. Anyway, the I used exactly your code and scenario didn't change.

Alexa says: "hum. Living room temperature is not responding".

I've also recreated the devices at https://alexa-node-red.bm.hardill.me.uk/devices and re-synced Alexa, but still the same result. Sorry.

hardillb commented 6 years ago

Is there any delay in the response? all responses need to be sent in less than 6 seconds

aleonnet commented 6 years ago

No delay at all. Alexa replies very quickly in about 1 second.

hardillb commented 6 years ago

OK, give this a try, it's a switch node that picks a different function node for all the different possible "heater" commands, you should wire the input/output nodes to each end

You should be able to copy and paste this into the input->clipboard space

It uses a global context key of test-temp to hold the targetTemperature if you set it via Alexa

[{"id":"a5b92c43.ebe95","type":"function","z":"71c66445.8e399c","name":"","func":"\nif (msg.payload < 10 || msg.payload > 30) {\n var range = {\n min: 10,\n max: 30\n }\n msg.payload = false;\n msg.extra = range;\n \n} else {\n \n global.set(\"test-temp\", msg.payload);\n\n msg.extra = {\n targetTemperature: {\n value: msg.payload\n }\n }\n msg.payload = true;\n}\n\nreturn msg;","outputs":"1","noerr":0,"x":416,"y":249,"wires":[["ce0b7d46.7ff11","9a0594e5.1e8de8"]]},{"id":"6a533282.cddedc","type":"switch","z":"71c66445.8e399c","name":"","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"SetTargetTemperatureRequest","vt":"str"},{"t":"eq","v":"GetTemperatureReadingRequest","vt":"str"},{"t":"eq","v":"TurnOnRequest","vt":"str"},{"t":"eq","v":"TurnOffRequest","vt":"str"},{"t":"eq","v":"GetTargetTemperatureRequest","vt":"str"},{"t":"else"}],"checkall":"true","outputs":6,"x":260.5,"y":282,"wires":[["a5b92c43.ebe95"],["70b745a4.3777b4"],["fdfe7c54.cbe358"],["fdfe7c54.cbe358"],["1b04c877.c29518"],["3229928f.91dd3e"]]},{"id":"3229928f.91dd3e","type":"function","z":"71c66445.8e399c","name":"","func":"var current = global.get(\"test-temp\");\n\nvar newtemp = current + msg.payload;\n\nif (newtemp < 10 || newtemp > 30) {\n var range = {\n min: 10,\n max: 30\n }\n msg.payload = false;\n msg.extra = range;\n} else {\n global.set(\"test-temp\", newtemp);\n msg.payload = true;\n msg.extra = {\n targetTemperature: {\n value: newtemp\n }\n }\n}\nreturn msg;","outputs":1,"noerr":0,"x":414.5,"y":402,"wires":[["ce0b7d46.7ff11","2ae2e453.1ea8d4"]]},{"id":"70b745a4.3777b4","type":"function","z":"71c66445.8e399c","name":"","func":"\nmsg.extra = {\n \"temperatureReading\": {\n \"value\": 21.5\n },\n \"applianceResponseTimestamp\": new Date().toISOString()\n};\nmsg.payload = true;\nreturn msg;","outputs":1,"noerr":0,"x":416,"y":286,"wires":[["ce0b7d46.7ff11","e26c7ffc.fc16d"]]},{"id":"fdfe7c54.cbe358","type":"function","z":"71c66445.8e399c","name":"","func":"msg.payload = true;\nreturn msg;","outputs":1,"noerr":0,"x":422.5,"y":326.25,"wires":[["ce0b7d46.7ff11","d294bb4a.9c4288"]]},{"id":"1b04c877.c29518","type":"function","z":"71c66445.8e399c","name":"","func":"var temp = global.get(\"test-temp\") || 22;\nmsg.extra = {\n \"targetTemperature\": {\n \"value\": temp\n },\n \"applianceResponseTimestamp\": new Date().toISOString(),\n \"temperatureMode\": {\n \"value\": \"AUTO\"\n }\n};\nmsg.payload = true;\n\nreturn msg;","outputs":1,"noerr":0,"x":416.5,"y":364.25,"wires":[["ce0b7d46.7ff11","16991ac0.123575"]]}]

aleonnet commented 6 years ago

There's must be something with the flow code format as I'm pasting just like the above message. image

hardillb commented 6 years ago

Github/the browser has probably added a load of new line chars, it should all be one line, try this:

[{"id":"a5b92c43.ebe95","type":"function","z":"71c66445.8e399c","name":"","func":"\nif (msg.payload < 10 || msg.payload > 30) {\n    var range = {\n        min: 10,\n        max: 30\n    }\n    msg.payload = false;\n    msg.extra = range;\n    \n} else {\n    \n    global.set(\"test-temp\", msg.payload);\n\n    msg.extra = {\n        targetTemperature: {\n            value: msg.payload\n        }\n    }\n    msg.payload = true;\n}\n\nreturn msg;","outputs":"1","noerr":0,"x":416,"y":249,"wires":[["ce0b7d46.7ff11","9a0594e5.1e8de8"]]},{"id":"6a533282.cddedc","type":"switch","z":"71c66445.8e399c","name":"","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"SetTargetTemperatureRequest","vt":"str"},{"t":"eq","v":"GetTemperatureReadingRequest","vt":"str"},{"t":"eq","v":"TurnOnRequest","vt":"str"},{"t":"eq","v":"TurnOffRequest","vt":"str"},{"t":"eq","v":"GetTargetTemperatureRequest","vt":"str"},{"t":"else"}],"checkall":"true","outputs":6,"x":260.5,"y":282,"wires":[["a5b92c43.ebe95"],["70b745a4.3777b4"],["fdfe7c54.cbe358"],["fdfe7c54.cbe358"],["1b04c877.c29518"],["3229928f.91dd3e"]]},{"id":"3229928f.91dd3e","type":"function","z":"71c66445.8e399c","name":"","func":"var current = global.get(\"test-temp\");\n\nvar newtemp = current + msg.payload;\n\nif (newtemp < 10 || newtemp > 30) {\n    var range = {\n        min: 10,\n        max: 30\n    }\n    msg.payload = false;\n    msg.extra = range;\n} else {\n    global.set(\"test-temp\", newtemp);\n    msg.payload = true;\n    msg.extra = {\n        targetTemperature: {\n            value: newtemp\n        }\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"x":414.5,"y":402,"wires":[["ce0b7d46.7ff11","2ae2e453.1ea8d4"]]},{"id":"70b745a4.3777b4","type":"function","z":"71c66445.8e399c","name":"","func":"\nmsg.extra = {\n    \"temperatureReading\": {\n        \"value\": 21.5\n    },\n    \"applianceResponseTimestamp\": new Date().toISOString()\n};\nmsg.payload = true;\nreturn msg;","outputs":1,"noerr":0,"x":416,"y":286,"wires":[["ce0b7d46.7ff11","e26c7ffc.fc16d"]]},{"id":"2ae2e453.1ea8d4","type":"debug","z":"71c66445.8e399c","name":"","active":true,"console":"false","complete":"true","x":594.5,"y":426,"wires":[]},{"id":"fdfe7c54.cbe358","type":"function","z":"71c66445.8e399c","name":"","func":"msg.payload = true;\nreturn msg;","outputs":1,"noerr":0,"x":422.5,"y":326.25,"wires":[["ce0b7d46.7ff11","d294bb4a.9c4288"]]},{"id":"1b04c877.c29518","type":"function","z":"71c66445.8e399c","name":"","func":"var temp = global.get(\"test-temp\") || 22;\nmsg.extra = {\n    \"targetTemperature\": {\n        \"value\": temp\n    },\n    \"applianceResponseTimestamp\": new Date().toISOString(),\n    \"temperatureMode\": {\n        \"value\": \"AUTO\"\n    }\n};\nmsg.payload = true;\n\nreturn msg;","outputs":1,"noerr":0,"x":416.5,"y":364.25,"wires":[["ce0b7d46.7ff11","16991ac0.123575"]]},{"id":"16991ac0.123575","type":"debug","z":"71c66445.8e399c","name":"","active":true,"console":"false","complete":"true","x":619,"y":380,"wires":[]},{"id":"d294bb4a.9c4288","type":"debug","z":"71c66445.8e399c","name":"","active":true,"console":"false","complete":"true","x":612,"y":336,"wires":[]},{"id":"e26c7ffc.fc16d","type":"debug","z":"71c66445.8e399c","name":"","active":true,"console":"false","complete":"true","x":608,"y":277,"wires":[]},{"id":"9a0594e5.1e8de8","type":"debug","z":"71c66445.8e399c","name":"","active":true,"console":"false","complete":"true","x":607,"y":236,"wires":[]}]
hardillb commented 6 years ago

That or if your on a mac it may have butchered all the quotes into pairs of smart quotes

aleonnet commented 6 years ago

It worked! Thank you.

Caxton1 commented 5 years ago

Hi, I found this thread while trying to do a similar thing with this skill. I have a temperature sensor which is connected to an esp8266 which is publishing the reading to node red using the topic LoungeAirTemp and that all works properly. I have added the sensor to the account that I created on your site and then added the skill to Alexa. I have added the appropriate nodes and pasted the code that you have published above. If I ask Alexa for the Lounge temperature, I get the answer 21.5 degrees so I know that that part works too. What I need to do next is to be able to substitute the fixed value in your code with the output from the temperature sensor but to be honest, it is more than a year since I have worked with node red and I am very rusty so I was hoping for a nudge in the right direction to save me a lot of time. Can you help?

hardillb commented 5 years ago

This issues was closed over a year ago, if you want help with basic Node-RED data handling please ask on Slack, the Node-RED forum or Stack Overflow

Caxton1 commented 5 years ago

Hi Ben,

Sorry, was having a brain freeze. Shortly after I posted the comment, I remembered that I could use a change node to set a flow to the msg.payload and then make a variable in the function and it all works.

Thanks

George

From: Ben Hardill notifications@github.com Sent: 09 September 2019 11:17 To: hardillb/node-red-alexa-home-skill-web node-red-alexa-home-skill-web@noreply.github.com Cc: Caxton1 george@georgekennedy.co.uk; Comment comment@noreply.github.com Subject: Re: [hardillb/node-red-alexa-home-skill-web] Devices not responding to requests (#45)

This issues was closed over a year ago, if you want help with basic Node-RED data handling please ask on Slack, the Node-RED forum or Stack Overflow

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hardillb/node-red-alexa-home-skill-web/issues/45?email_source=notifications&email_token=AIJU3Y5HL7Y3AO5R25EHDTTQIYO75A5CNFSM4EQSMVDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6HAMWA#issuecomment-529401432 , or mute the thread https://github.com/notifications/unsubscribe-auth/AIJU3Y2FFCZGZBIQJNNWVSLQIYO75ANCNFSM4EQSMVDA . https://github.com/notifications/beacon/AIJU3YZ3BBVRPCFBUYXK2H3QIYO75A5CNFSM4EQSMVDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6HAMWA.gif