Announcement

Collapse
No announcement yet.

Alexa TTS including variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Alexa TTS including variables

    I have HS4 events speaking and including variables, for example

    Speak mike, your sauna has reached a temperature of $$DVR:2602: degrees

    Could I replicate that with node-red-contrib-alexa-remote2 (or another pallete)

    #2
    I'm not sure how you are sending data from HS to Node-Red, but this is an option and how I do it:

    Add an action to your HS speak event. Pick the Send MQTT Message action (provided by mcsMQTT plugin). I structure the message like this:

    Code:
    Alexa/Speak/Living Room=$$DSR:(855):
    Code:
    $$DSR:(855):
    is replaced with the Status of Device with Ref=855. Refer to the mcsMQTT manual for more examples.

    In Node-Red, I have the "MQTT in" node listening for Alexa/# and a function node parsing out the different parts of the topic in between the slashes. This routes to the correct Echo device and differentiates between Speak, Announce, Whisper, etc. The payload is the text to be spoken.

    Comment


      #3
      I was dreading that answer... I have mcsMQTT installed, but only use if to control my Daikin AC's (which doesnt require any understanding of the PI as its just entering their IP in a tab). I looked at understanding the PI but gave up shortly after... I might have to have another go. I was going to do the post with saying please dont tell me I have to use MQTT ... lol

      Would you mind screen grabbing the mqtt in and funcion ? And I guess i have to set up a mqtt broker in the HS PI ?

      Comment


        #4
        Originally posted by AZweimiller View Post
        I'm not sure how you are sending data from HS to Node-Red, but this is an option and how I do it:..
        I loaded up your sample code. It is a really nice solution. Thanks for sharing it.

        Comment


          #5
          Originally posted by mikee123 View Post
          I was dreading that answer... I have mcsMQTT installed, but only use if to control my Daikin AC's (which doesnt require any understanding of the PI as its just entering their IP in a tab). I looked at understanding the PI but gave up shortly after... I might have to have another go. I was going to do the post with saying please dont tell me I have to use MQTT ... lol

          Would you mind screen grabbing the mqtt in and funcion ? And I guess i have to set up a mqtt broker in the HS PI ?
          mcsMQTT has a broker built in.

          You can also import the code for a flow. Here is the code for AZweimiller example, which he provided in his original post of how to do this. Just select the mahburger menu in node red and select import. You can then paste the code below and it will magically build the flow.


          [CODE][
          {
          "id": "c8beba27.66b5f8",
          "type": "mqtt in",
          "z": "66eaccac.f57ca4",
          "name": "",
          "topic": "Alexa/#",
          "qos": "2",
          "datatype": "auto",
          "broker": "9b237e82.01cc8",
          "x": 150,
          "y": 60,
          "wires": [
          [
          "5270d151.870c9"
          ]
          ]
          },
          {
          "id": "c86e9281.ec90d",
          "type": "inject",
          "z": "66eaccac.f57ca4",
          "name": "Test, Speaking",
          "props": [
          {
          "p": "payload"
          },
          {
          "p": "topic",
          "vt": "str"
          }
          ],
          "repeat": "",
          "crontab": "",
          "once": false,
          "onceDelay": 0.1,
          "topic": "Alexa/Speak/Basement",
          "payload": "Test, Speaking",
          "payloadType": "str",
          "x": 200,
          "y": 120,
          "wires": [
          [
          "5270d151.870c9"
          ]
          ]
          },
          {
          "id": "32728066.12deb",
          "type": "alexa-remote-routine",
          "z": "66eaccac.f57ca4",
          "name": "Alexa Speak",
          "account": "f292f40d.a814e8",
          "routineNode": {
          "type": "custom",
          "payload": {
          "type": "msg",
          "value": "payload"
          }
          },
          "x": 670,
          "y": 60,
          "wires": [
          []
          ]
          },
          {
          "id": "5270d151.870c9",
          "type": "function",
          "z": "66eaccac.f57ca4",
          "name": "MQTT >> Alexa Speak",
          "func": "var topic = msg.topic.split(\"/\");\nvar TextToSpeak = msg.payload\n\nif (topic.length==4) {\n msg.payload = { type: 'speakAtVolume', payload: { type: 'regular', text: 'Oh, ohhh... something went wrong...!', volume: 50, devices: ['Everywhere'] }};\n msg.payload.payload.volume = topic[3];\n} else {\n msg.payload = { type: 'speak', payload: { type: 'regular', text: 'Oh, ohhh... something went wrong...', devices: ['Everywhere']}};\n} \n \nif (topic[1] == \"Speak\") {\n msg.payload.payload.type = \"regular\";\n msg.payload.payload.text = TextToSpeak\n } \n else if (topic[1] == \"Announce\")\n {\n msg.payload.payload.type = \"announcement\";\n msg.payload.payload.text = TextToSpeak\n }\n \n else if (topic[1] === \"Whisper\")\n {\n msg.payload.payload.type = \"ssml\";\n msg.payload.payload.text = '<speak><amazon:effect name=\"whispered\">' + TextToSpeak + '</amazon:effect></speak>'\n }\n \n \n \n\n // \n\n \n \n if ((topic[2] == \"ALL\") || (topic[2] == \"Everywhere\")) {\n msg.payload.payload.devices[0] = \"Everywhere\";\n } else {\n msg.payload.payload.devices[0] = topic[2];\n }\n \n\n \n\n\n return msg;\n\n\n\n\n\n",
          "outputs": 1,
          "noerr": 0,
          "initialize": "",
          "finalize": "",
          "x": 420,
          "y": 60,
          "wires": [
          [
          "32728066.12deb",
          "f4afe529.665828"
          ]
          ]
          },
          {
          "id": "f4afe529.665828",
          "type": "debug",
          "z": "66eaccac.f57ca4",
          "name": "",
          "active": true,
          "tosidebar": true,
          "console": false,
          "tostatus": false,
          "complete": "true",
          "targetType": "full",
          "x": 650,
          "y": 120,
          "wires": []
          },
          {
          "id": "5d70ebf8.01a8c4",
          "type": "inject",
          "z": "66eaccac.f57ca4",
          "name": "Test, Whisper",
          "props": [
          {
          "p": "payload"
          },
          {
          "p": "topic",
          "vt": "str"
          }
          ],
          "repeat": "",
          "crontab": "",
          "once": false,
          "onceDelay": 0.1,
          "topic": "Alexa/Whisper/Basement",
          "payload": "Test, Whisper",
          "payloadType": "str",
          "x": 190,
          "y": 160,
          "wires": [
          [
          "5270d151.870c9"
          ]
          ]
          },
          {
          "id": "b1e04630.cc57d8",
          "type": "inject",
          "z": "66eaccac.f57ca4",
          "name": "Test, Announce",
          "props": [
          {
          "p": "payload"
          },
          {
          "p": "topic",
          "vt": "str"
          }
          ],
          "repeat": "",
          "crontab": "",
          "once": false,
          "onceDelay": 0.1,
          "topic": "Alexa/Announce/Basement",
          "payload": "Test, Announce",
          "payloadType": "str",
          "x": 200,
          "y": 200,
          "wires": [
          [
          "5270d151.870c9"
          ]
          ]
          },
          {
          "id": "5df66b63.6f6b14",
          "type": "inject",
          "z": "66eaccac.f57ca4",
          "name": "Test, Announce - Everywhere",
          "props": [
          {
          "p": "payload",
          "v": "Test, Announce",
          "vt": "str"
          },
          {
          "p": "topic",
          "v": "Alexa/Announce/ALL",
          "vt": "string"
          }
          ],
          "repeat": "",
          "crontab": "",
          "once": false,
          "onceDelay": 0.1,
          "topic": "Alexa/Announce/ALL",
          "payload": "Test, Announce",
          "payloadType": "str",
          "x": 240,
          "y": 240,
          "wires": [
          [
          "5270d151.870c9"
          ]
          ]
          },
          {
          "id": "9b237e82.01cc8",
          "type": "mqtt-broker",
          "z": "",
          "name": "@Home_mqtt",
          "broker": "192.168.254.70",
          "port": "1883",
          "clientid": "SightHound",
          "usetls": false,
          "compatmode": false,
          "keepalive": "60",
          "cleansession": true,
          "birthTopic": "",
          "birthQos": "0",
          "birthPayload": "",
          "closeTopic": "",
          "closeQos": "0",
          "closePayload": "",
          "willTopic": "",
          "willQos": "0",
          "willPayload": ""
          },
          {
          "id": "f292f40d.a814e8",
          "type": "alexa-remote-account",
          "z": "",
          "name": "Home",
          "authMethod": "proxy",
          "proxyOwnIp": "YOUR_IP_ADDRESS",
          "proxyPort": "3456",
          "cookieFile": "AuthFile",
          "refreshInterval": "3",
          "alexaServiceHost": "pitangui.amazon.com",
          "amazonPage": "amazon.com",
          "acceptLanguage": "en-US",
          "userAgent": "",
          "useWsMqtt": "on",
          "autoInit": "on"
          }
          ][CODE]

          Comment


            #6
            Originally posted by drhtmal View Post

            mcsMQTT has a broker built in.
            Yes I got the mqtt in node to say connected. thats a good start. But still lost as to what exactly to input into mqtt in and the function

            Comment


              #7
              Ok something has gone horribly wrong. I created the flow from the code in a new tab. On my Alexa routine node it now says port 3456 already in use. I deleted that new flow and copied it into my existing flow. Same thing. Restarted node red, error is still there

              Attached Files

              Comment


                #8
                I changed the port, and all is good again. But not sure why this error came up.

                And my MQTT in is now not connecting any more. Even though I canged to my configuration which connected before

                Restarting the mcsMQTT PI and MQTT in is connected now. I got the test buttons to work. But when I send the following via an event, nothing happens, and nothing to see in the debug panel either

                Attached Files

                Comment


                  #9
                  Is the action enabled?

                  Comment


                    #10
                    Originally posted by drhtmal View Post
                    Is the action enabled?
                    Yep. Just checked again to make sure. And the edited Inject 'Test Speaking' button works.
                    Attached Files

                    Comment


                      #11
                      If the inject "Test, Speaking" node is working then there must be something wrong with sending/receiving the MQTT message into the "Alexa/#" node from your event. I have this working on my system so I know it works.

                      Comment


                        #12
                        Maybe try taking out the substitution variable as a test

                        Comment


                          #13
                          Originally posted by drhtmal View Post
                          Maybe try taking out the substitution variable as a test
                          Yes I did that. Still no joy. Do I need to change anything in the mcsMQTT PI, and in node-red in the function ? I adjusted the MQTT in and Alexa routines for my settings, but did not touch the function.
                          Is there any way seeing what HS4 is sending via MQTT message to be able to debug ? I have attached a debug in node red to the MQTT in but thats not showing anything (maybe that needed changing ?)

                          Comment


                            #14
                            I have never used the builtin MQTT broker in mscMQTT.

                            Comment


                              #15
                              I can't get the internal broker in mcsMQTT to work. You might inquire in the mcsMQTT forum on troubleshooting

                              Comment

                              Working...
                              X