Announcement

Collapse
No announcement yet.

Control a virtual switch in different rooms using the same phrase?

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

    Control a virtual switch in different rooms using the same phrase?

    I want to say "Reading Mode ON" in three different rooms and depending on which room I am speaking in it will trigger that virtual switch. How would I set this up using Node-red? Anybody have a flow like this?

    #2
    What are you using to receive the spoken phrase, Alexa, Google Assistant, other?
    Karl S
    HS4Pro on Windows 10
    1070 Devices
    56 Z-Wave Nodes
    104 Events
    HSTouch Clients: 3 Android, 1 iOS
    Google Home: 3 Mini units, 1 Pair Audios, 2 Displays

    Comment


      #3
      I am using two echo dots and one Sonos One.

      Comment


        #4
        There's a Alexa node that will trigger everytime you say anything to any Echo device on your account. Even just asking the weather, etc. It passes the phrase and the name of the Device that heard the command. Just route based on the Echo device name and control your different virtual devices.

        If you don't mind saying Alexa, tell homeseer Reading Mode On then you could do this even easier.

        Comment


          #5
          AZweimiller could you get a full message out of an Alexa node and provide the device name so we can be sure of where it is stored? I don't have an Alexa to test with. Also, is there more than one Alexa contrib? If so, which one do you use? pcgirl65 if you have Node Red and Alexa wishing together feel free to send the output as well. Just be sure to wrap it in code tags, please. From there we can set up an example or seven.
          Karl S
          HS4Pro on Windows 10
          1070 Devices
          56 Z-Wave Nodes
          104 Events
          HSTouch Clients: 3 Android, 1 iOS
          Google Home: 3 Mini units, 1 Pair Audios, 2 Displays

          Comment


            #6
            Yes, I'll look tomorrow. Node-Red is impossible to navigate even to look at a node name while on mobile, hence my generalities.

            Comment


              #7
              Originally posted by AZweimiller View Post
              There's a Alexa node that will trigger everytime you say anything to any Echo device on your account. Even just asking the weather, etc. It passes the phrase and the name of the Device that heard the command. Just route based on the Echo device name and control your different virtual devices.

              If you don't mind saying Alexa, tell homeseer Reading Mode On then you could do this even easier.
              Do you have an example of this node?

              Comment


                #8
                Hopefully I can share one tonight.

                I curently have a couple setup for each room so I can just say turn on light or turn on fan without being room specific.

                Sent from my SM-G960U1 using Tapatalk

                Comment


                  #9
                  pcgirl65 ,

                  I saw you posted this elsewhere : https://community.hubitat.com/t/node-red-flow-samples-sharing/45207/146
                  It looks impressive! Did you try it?


                  If you are wondering about the green nodes (they seem Habitat device nodes), I can't find them but you don't even need them. Just import the code then once you have finished referencing them with your own HS Device Nodes against each one then delete them

                  Change the serial numbers in the switch node to your own.

                  Eman.
                  TinkerLand : Life's Choices,"No One Size Fits All"

                  Comment


                    #10
                    Eman In am very new to Node red so I am working my way through. I am also following this one https://community.home-assistant.io/...ode-red/165399 which is what I am looking for also. I did this one and it seems to work but I will try to make it better with these two examples.

                    Click image for larger version

Name:	screencapture-192-168-1-15-1880-2020-10-23-11_37_37.png
Views:	389
Size:	46.9 KB
ID:	1428071

                    Comment


                      #11
                      The example Eman referenced uses 2 Switch Nodes from the original Alexa Output. The first just Filters for the desired phrase. If the received spoken phrase matches accepted parameters, the flow continues. If it does not, then it ends at that Switch node. This is connected (wired) to a second Switch node, which uses the device's reported serial number. This is found in msg.payload.dviceSerialNumber and is used to create a connection for each Echo device. This one is shown below.
                      Click image for larger version

Name:	hs3.png
Views:	395
Size:	31.1 KB
ID:	1428083

                      Are you using Alexa routines to then set the HomeSeer device? I would probably use Node Red to do this. But not knowing the Alexa paradigm, I could be wrong on that part. My reasoning for using the Node Red flow is that it eliminates a hop and also, depending on your setup, may eliminate an internet hop.

                      From there you can wire in the appropriate HomeSeer device and control it as needed. You may also have Alexa respond on success/failure. I personally would change the HomeSeer device and then respond as a final action, but you could just add the HomeSeer device change on the end OR pull a second wire from the Switch Node and go to the HomeSeer Device control. The question there becomes do you want a linear program view?

                      I would deal with setting the msg to have a value for On/Off or whatever you need to set your HomeSeer Device to between the two above mentioned switches. This way you set the Status/Value in a single node. If you do it later you could use a subflow but there is no need so I would not suggest such.

                      Note that you will need to make changes to the msg object in order to control the HomeSeer Device. How you do this is up to you.
                      Karl S
                      HS4Pro on Windows 10
                      1070 Devices
                      56 Z-Wave Nodes
                      104 Events
                      HSTouch Clients: 3 Android, 1 iOS
                      Google Home: 3 Mini units, 1 Pair Audios, 2 Displays

                      Comment


                        #12
                        I took a look at my Flow. The screenshots above look like the Alexa nodes that I am using. The name of the Echo device is stored in msg.payload.name. This is probably easier than a serial number.

                        My goals are different than pcgirl65 but this is what I have:

                        1) I have a Switch node right after "On Device Activity". This switch node only passes if payload.domainAttributes == NULL. I found that this really helped filter out false triggers. For example, if two Alexa devices hear the wake word and phrase, Alexa will only reply on the device that it determines heard you the best. Unfortunately you still get two triggers from "On Device Activity", one from each device that heard the wake word. The good news is that the extraneous trigger has domainAttributes set while real triggers do not. It's a reliable filter for me.

                        2) I use a change node to remove the wake word (Alexa in my case) from the spoken phrase. The phrase is stored in msg.payload.description.summary. I set the rule to "Change" and look for "alexa" and replace with "". Next is another switch node:

                        3) Because EVERYTHING you say to Alexa will trigger "On Device Activity", I have a Switch node that only passes certain phrases. I check msg.payload.description.summary against a regex that looks like this: "(turn (on|off)|set|dim) (the )? (television|fan|lamps)". This allows me to give several commands to either the television, the fan, or the lamps. This switch node passes the output to my another change node:

                        3) This change node takes the spoken phrase, which again is in msg.payload.description.summary and uses regex to add the Alexa device name (msg.payload.name) in a strategic place. If my Alexa device is named "Living Room" and I say "Turn on the lamps", this change node combines these items into "Turn on the Living Room lamps". In addition to building the new voice command phrase, it builds a URL to my HS instance JSON interface. This is accomplished with a Jsonata expression:

                        Code:
                        (    $pattern := $eval("/^(.+) (television|fan|lamps)/");    "https://homeseer.zweimiller.com/JSON?request=voicecommand&phrase=" & $replace(payload.description.summary, $pattern, "$1 " & payload.name & " $2")    )
                        This constructed URL is saved to msg.url which leads to my last node:

                        4) HTTP Request. It just hits the URL from above and Homeseer will react. Modifying the spoken phrase and passing it along to Homeseer's voice processing engine means I do not have to add HS device nodes in NR for every fan, lamp and television that I have in every room. Homeseer just "figures it out" based on the voice command phrase. It's simple and extendable. The only requirement is that the Alexa device name match the device name. An Alexa named Living Room means my fan must be Living Room Fan, and TV as Living Room Television, etc.

                        This isn't exactly what OP is trying to do but it may offer some ideas.

                        Comment


                          #13
                          AZweimiller Your flow seems to start off very similar to the one I referenced above in the home-assitant forum but then you take it to a whole other level! This is really interesting and a great way to learn how to use node red. Thanks!

                          Can you supply the flow code so I can see what you are doing?

                          Comment


                            #14
                            Originally posted by AZweimiller View Post
                            I took a look at my Flow. The screenshots above look like the Alexa nodes that I am using. The name of the Echo device is stored in msg.payload.name. This is probably easier than a serial number.

                            My goals are different than pcgirl65 but this is what I have:

                            1) I have a Switch node right after "On Device Activity". This switch node only passes if payload.domainAttributes == NULL. I found that this really helped filter out false triggers. For example, if two Alexa devices hear the wake word and phrase, Alexa will only reply on the device that it determines heard you the best. Unfortunately you still get two triggers from "On Device Activity", one from each device that heard the wake word. The good news is that the extraneous trigger has domainAttributes set while real triggers do not. It's a reliable filter for me.

                            2) I use a change node to remove the wake word (Alexa in my case) from the spoken phrase. The phrase is stored in msg.payload.description.summary. I set the rule to "Change" and look for "alexa" and replace with "". Next is another switch node:

                            3) Because EVERYTHING you say to Alexa will trigger "On Device Activity", I have a Switch node that only passes certain phrases. I check msg.payload.description.summary against a regex that looks like this: "(turn (on|off)|set|dim) (the )? (television|fan|lamps)". This allows me to give several commands to either the television, the fan, or the lamps. This switch node passes the output to my another change node:

                            3) This change node takes the spoken phrase, which again is in msg.payload.description.summary and uses regex to add the Alexa device name (msg.payload.name) in a strategic place. If my Alexa device is named "Living Room" and I say "Turn on the lamps", this change node combines these items into "Turn on the Living Room lamps". In addition to building the new voice command phrase, it builds a URL to my HS instance JSON interface. This is accomplished with a Jsonata expression:

                            Code:
                            (    $pattern := $eval("/^(.+) (television|fan|lamps)/");    "https://homeseer.zweimiller.com/JSON?request=voicecommand&phrase=" & $replace(payload.description.summary, $pattern, "$1 " & payload.name & " $2")    )
                            This constructed URL is saved to msg.url which leads to my last node:

                            4) HTTP Request. It just hits the URL from above and Homeseer will react. Modifying the spoken phrase and passing it along to Homeseer's voice processing engine means I do not have to add HS device nodes in NR for every fan, lamp and television that I have in every room. Homeseer just "figures it out" based on the voice command phrase. It's simple and extendable. The only requirement is that the Alexa device name match the device name. An Alexa named Living Room means my fan must be Living Room Fan, and TV as Living Room Television, etc.

                            This isn't exactly what OP is trying to do but it may offer some ideas.
                            Would really like to see the switch node for option one to reduce false triggers when 2 Alexa hear the command

                            Sent from my SM-G960U1 using Tapatalk

                            Comment


                              #15
                              Originally posted by mbg0333 View Post
                              Would really like to see the switch node for option one to reduce false triggers when 2 Alexa hear the command

                              Sent from my SM-G960U1 using Tapatalk
                              Not much to see, it's pretty much exactly like I described:

                              Click image for larger version

Name:	Capture.PNG
Views:	335
Size:	40.9 KB
ID:	1428138

                              Comment

                              Working...
                              X