Announcement

Collapse
No announcement yet.

Alexa TTS that works better (IMHO) than the solution for Home Assistant.

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

    #16
    Which flow are you using ?
    Mine or something else?

    Which MQTT method in HomeSeer are you using ?


    [EDIT]

    OK, so, the alexa nodes in node-red does not read MQTT by default, so you can't just pass the MQTT data directly into one of them and expect it to work.

    You have to parse/split the message up into a friendlier format which is what my flow does (1st post).
    Copy it from that post and paste it into a new flow, add your account info and modify the MQTT listener and you should be good to go.

    Click image for larger version

Name:	Untitled.png
Views:	1622
Size:	23.6 KB
ID:	1325977
    Click image for larger version

Name:	Capture2.PNG
Views:	1565
Size:	16.5 KB
ID:	1325978

    Comment


      #17
      Thanks, I will import your flow again and do some trials.

      mr.Magoo
      EDIT: I didn't have the first flow loaded in Node-Red! After I did that I was able to send a TTS message to one of my echos! Now the fun begins. Thank you.

      Comment


        #18
        Just a thank you for introducing me to node red. Took the plunge and just installed node.js and node red on my windows HS server, and boy is it quick and barely uses any resources.

        The Alexa TTS is way quicker than running a batch file, and it was a bit awkward getting it to work for the UK - the settings I had to use were:
        Service host: layla.amazon.co.uk
        Page: alexa.amazon.co.uk
        Language: en-GB

        Loving the way node red works - I've converted a few scripts to flows, and made it run a MQTT server that speaks or sends notifications near instantly.
        It even allows control of harmony stuff with the pallette package, which I'm now playing with

        Comment


          #19
          Thanks - glad you like it !


          SSML is pretty fun to play with and the ability to trigger things based of the "Alexa Event" node is pretty neat.

          For other that are not convinced yet and just reading... Alexa Event is a trigger that get's fired on any type of Alexa activity and you can use data such as what was said, when, which device, etc. to trigger additional actions.

          Another Node that you may want to look into is "Alexa Local" - https://flows.nodered.org/node/node-...ib-alexa-local
          This allows you to set up a "virtual" device in Node Red that is recognized by Alexa as a smart home device and you can either have it trigger things directly - or - when you combine the two (Alexa Local and Alexa Event) you can use it to make the triggering room sensitive in a way not too different from Alexa's own Group/Lights function (but more powerful / flexible).

          i.e. you combine the room from Events with the device from Local and let that control whatever it is you'd like to control

          Comment


            #20
            Wow. I was looking into other things to do and that looks like something I can tinker with.

            Any more nuggets you care to share?

            Comment


              #21
              Ok, so I've started putting in flows in node-red as homeseer PI replacements as some of the PIs do tend to hit the cpu.

              BLLAN - uninstalled and created a flow that sets virtual devices - even having logic to alert based on if the latency is too high. This saved around 5-10% cpu, as its very cpu intensive especially if you want to ping often.
              HA bridge - completely replaced using the alexa nodes.
              Notifications for fire TV - bit "fun" that one - tried to natively construct a multipart HTTP post with file in node-red, but couldn't - it seems the "filename" form name conflicts with the internal processing of the http request module, so stops the post from working.
              So, after failing with JS, I decided to leverage the notify python used by home assistant. Using pynodered, created a function and now its a node within node-red. Hey presto, near instant notifications with a jpg from the front door cam if needed.

              Now that I've got pynodered, this opens up way more doors as I can leverage homeassistant stuff. Next on the agenda is ADB control which doesn't rely on shelling and taking 5 seconds to spin up.

              Comment


                #22
                Originally posted by Furious View Post
                Ok, so I've started putting in flows in node-red as homeseer PI replacements as some of the PIs do tend to hit the cpu.


                Notifications for fire TV - bit "fun" that one - tried to natively construct a multipart HTTP post with file in node-red, but couldn't - it seems the "filename" form name conflicts with the internal processing of the http request module, so stops the post from working.
                So, after failing with JS, I decided to leverage the notify python used by home assistant. Using pynodered, created a function and now its a node within node-red. Hey presto, near instant notifications with a jpg from the front door cam if needed.
                How can I get more info on notifications to fire Tv?

                Comment


                  #23
                  What do you need to know?

                  Comment


                    #24
                    Originally posted by mr.Magoo View Post
                    OK, so there's many ways to skin a cat and I personally find this better than the solution for HomeAssistant and better than the ChromeCast Plugin ( it is for me, not here to start a debate). While I got HomeAssistant kind of, sort of working semi well I had issues with cookies and the interface (or lack there of) was limiting.
                    Chromecast works beautifully on a Google Home, but I'm stuck in the Amazon echo-system and using it for announcements having both in a box kind of works but the sound quality is poor and there's a long delay, so...

                    This solution requires Node-Red
                    Maybe you can port it, but then again, a PI Zero W is $5 so it's hardly worth the hassle even if you'd only run this application.
                    I find myself using it as a DB Writer between Homeseer and InfluxDB, I use it to pull weather from DarkSky, I have one as a 1W interface, etc. etc. so there's a lot of usages for it.
                    ...


                    CELEBRATION! I've been able to successfully get this up and running after about half a day of poking around and learning a LOT!

                    My Observations:
                    1. Installation of node.js / installing node-red and the related alexa remote packages were pretty straight forward but the overall concept was not very well explained. Guess that's how we all learn - by trial and error.
                    2. The step by step was helpful - especially for the process of saving the authentication cookie.
                    3. MQTT is serious overkill if all you want to do is simply get TTS to work over Alexa devices. it requires an HS3 plugin for mcsMQTT and also would require a MQTT broker (mosquittto) which again is a lot of churn for little gain. Maybe I'll see a use for that if I expand out IoT more significantly in the future.
                    4. An easier way to implement without MQTT is to setup a set some HTTP IN nodes in node-red that do the same and simply direct what you need into speech routines - this can be done elegantly and simply inside HS3 also with basic URL calls.
                    5. Alexa SSML and the Polly (Ivona voices) that they acquired are really fun to play with. Joey used to be my HomeSeer voice and now he is back to complement Alexa for around the house.
                    6. Last observation after experimenting is that I am 100% confident that code could be implemented as a HS4 plugin that would expose the same functions and would eliminate a lot of complexity and overhead of setting up node.js / node-red / and the other packages to extend what people have been asking for from HS regarding Alexa integrations. (Wonder if HomeSeer is considering this for the next wave?).

                    Good stuff overall though, and many thanks to Mr. Magoo and everyone else that has contributed pieces to make this work. My house is talking to me again after several of the speaker clients and remote media PC's had been deprecated by the use of FireTV and AppleTV devices and a dozen Amazon Echo's scattered throughout the house.

                    ---Lee III

                    Comment


                      #25
                      Nicely done.
                      Mqtt is so easy to implement in node red for both client and server, as its literally just a node install and all flows can use the server. A bit overkill, but allows expansion - also, the flows use hardly any cpu.
                      I'm not kidding, my server was running 20-40% cpu with the HS plugins needed, and now runs 10-20% with node red which also serves as a habridge replacement with 20 devices, replaced the harmony PI with a flow, implemented a network monitor flow, a file sync flow, mqtt, etc. My server has 80% free cpu now to add even more.

                      I'm now looking into what else I can easily integrate, as coding is no longer a chore - mostly I was put off by most things as the windows platform is not the one used by hobbyists like us, and coming up with workarounds or re-engineer existing phthon, JS or other linux stuff never worked well.
                      I can code in the 2 main languages without a delay of loading yet another shell, and not constantly reinvent the wheel.

                      Comment


                        #26
                        I installed node-js and node-red under WSL (Windows Subsystem for Linux) on my Win 10 Homeseer Server today. Fairly easy using ubuntu instructions under WSL (I also have influx-db installed under WSL).

                        I managed to get the flows configured, but I get the error "invalid sequence node" if I use Alexa/Speak, but Alexa/Announce works fine to my echo devices. Any thoughts about the speak error?

                        Comment


                          #27
                          Originally posted by Furious View Post
                          What do you need to know?
                          I have the node-red and alexa TTS working, python and a MQTT broker. What app if any on the fire stick/tv do i need? Do you have a flow a person could import?

                          Comment


                            #28
                            Originally posted by mterry63 View Post
                            I installed node-js and node-red under WSL (Windows Subsystem for Linux) on my Win 10 Homeseer Server today. Fairly easy using ubuntu instructions under WSL (I also have influx-db installed under WSL).

                            I managed to get the flows configured, but I get the error "invalid sequence node" if I use Alexa/Speak, but Alexa/Announce works fine to my echo devices. Any thoughts about the speak error?
                            Answering my own question, the first Speak node has the wrong variable name, the posted flow says msg.testtospeak and it should be msg.texttospeak

                            Comment


                              #29
                              Hmmm... guess I need to double check that flow again....

                              For others looking at this thread, there's no need to install node-JS and node red under Linux (on Windows) unless you'd like to for some reason, both run fine under Windows itself.
                              Only thing I'd recommend doing is installing it as global packages and move the temp files to a location which your user/service has access to (if set up to run as a service).

                              Someone mentioned that MQTT is overkill, yes it is for TTS only - then again, it's very easy to install and set up and I find it easier to use than webhooks and it's WAY easier to use if you want to send data from HS to other things... as mentioned in the initial post, I use MQTT as the transport to get my HS data into Influx Database and vise versa.

                              Comment


                                #30
                                Originally posted by thomauto@aol.com View Post

                                I have the node-red and alexa TTS working, python and a MQTT broker. What app if any on the fire stick/tv do i need? Do you have a flow a person could import?
                                From the amazon store, install "notifications for fire tv" - install it, and run it, it then stays loaded even after reboot.
                                This is basically a http server which listens on port 7676 - waiting for something to be posted to the server.

                                So, next up , here's my flow which listens for the "Notify" topic and then triggers the call out to python:
                                Code:
                                [{"id":"f30bf535.f431e8","type":"function","z":"7b1d3f60.25be3","name":"Parse Message","func":"        var tokens = msg.topic.split(\"/\");\n        flow.set('mesg',msg.payload);\n        flow.set('dura',tokens[1]);\n        //flow.set('device',tokens[2]);\n        return msg;","outputs":1,"noerr":0,"x":200,"y":140,"wires":[["bdfd1ea6.c36d9","95e86db8.5fc88","c430c66f.865108"]]},{"id":"c430c66f.865108","type":"debug","z":"7b1d3f60.25be3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":40,"wires":[]},{"id":"853a5483.a4bb88","type":"debug","z":"7b1d3f60.25be3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":770,"y":140,"wires":[]},{"id":"d6af2709.e62048","type":"send_notify","z":"7b1d3f60.25be3","x":590,"y":140,"wires":[["853a5483.a4bb88"]]},{"id":"bdfd1ea6.c36d9","type":"change","z":"7b1d3f60.25be3","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"mesg","tot":"flow"},{"t":"set","p":"server","pt":"msg","to":"192.168.5.135","tot":"str"},{"t":"set","p":"duration","pt":"msg","to":"dura","tot":"flow"},{"t":"set","p":"file","pt":"msg","to":"C:\\Program Files (x86)\\HomeSeer HS3\\html\\netcam\\currentimage.jpg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":140,"wires":[["d6af2709.e62048"]]},{"id":"95e86db8.5fc88","type":"change","z":"7b1d3f60.25be3","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"mesg","tot":"flow"},{"t":"set","p":"server","pt":"msg","to":"192.168.5.146","tot":"str"},{"t":"set","p":"duration","pt":"msg","to":"dura","tot":"flow"},{"t":"set","p":"file","pt":"msg","to":"C:\\Program Files (x86)\\HomeSeer HS3\\html\\netcam\\currentimage.jpg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":200,"wires":[["d6af2709.e62048"]]},{"id":"20969819.9690e8","type":"mqtt in","z":"7b1d3f60.25be3","name":"","topic":"Notify/#","qos":"0","datatype":"auto","broker":"bc36b861.c8f2a8","x":100,"y":60,"wires":[["f30bf535.f431e8"]]},{"id":"bc36b861.c8f2a8","type":"mqtt-broker","z":"","name":"MQTTSERVER","broker":"127.0.0.1","port":"1883","clientid":"myClient","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
                                Import this flow after you've installed the below:

                                Next up - install pynodered:
                                https://pypi.org/project/pynodered/

                                So, you need to have a function to shell out to. Here's my two functions for notify and also send ADB commands - save it as notify.py somewhere:
                                Code:
                                from pynodered import node_red
                                import base64
                                import io
                                import logging
                                import sys
                                
                                import requests
                                from requests.auth import HTTPBasicAuth, HTTPDigestAuth
                                import voluptuous as vol
                                import os
                                import time
                                
                                @node_red(category="pyfuncs")
                                def send_notify(node, msg):
                                    remoteip = msg['server']
                                    duration1 = msg['duration']
                                    message = msg['payload']
                                    fileup = msg['file']
                                    fontsize = 0
                                    position = 0
                                    transparency = 0
                                    color = "#607d8b"
                                    interrupt = False
                                    timeout = 5
                                    target=F"http://{remoteip}:7676"
                                    file_as_bytes = open(fileup, "rb")
                                    """Send a message to a Android TV device."""
                                    payload = dict(
                                        filename=(
                                            "image",
                                            file_as_bytes,
                                            "application/octet-stream",
                                            {"Expires": "0"},
                                        ),
                                        type="0",
                                        title="Notification",
                                        msg=message,
                                        duration=duration1,
                                        fontsize=0,
                                        position=0,
                                        bkgcolor=color,
                                        transparency=0,
                                        offset=0,
                                        app="Notifications for Fire TV",
                                        force="true",
                                        interrupt="False",
                                    )
                                
                                    try:
                                        response = requests.post(target, files=payload, timeout=5)
                                        msg['payload'] = str(response)
                                        if response.status_code != 200:                
                                            _LOGGER.error("Error sending message: %s", str(response))
                                            msg['payload'] = "Error sending message: %s", str(response)
                                    except requests.exceptions.ConnectionError as err:
                                            _LOGGER.error("Error communicating with %s: %s", target, str(err))
                                            msg['payload'] = "Error communicating with %s: %s", target, str(err)
                                    return msg
                                
                                @node_red(category="pyfuncs")
                                def send_adb(node, msg):
                                    totaloutput = []
                                    remoteip = msg['server']
                                    cmdargs = msg['payload']
                                    path = msg['path']
                                    os.chdir(path)
                                    connect = os.popen("adb connect " + remoteip + ":5555" ).read()
                                    print(connect)
                                    length = len(cmdargs)
                                    for i in range(length):
                                        if "timeout" in cmdargs[i]:
                                            timsecs = cmdargs[i]
                                            timsecs2 = int(timsecs[-2:])
                                            time.sleep(timsecs2)
                                        else:
                                            output = os.system("adb -s " + remoteip + ":5555" + " " + cmdargs[i])
                                            print(output)
                                            totaloutput.append(output)
                                    msg['payload'] = totaloutput
                                    return msg
                                Next up - you have to launch pynode red first so that node-red can load the function nodes.
                                In my server startup script, I have the following to load them:
                                Code:
                                c:\scripts\pskill pynodered.exe
                                start cmd /k "pynodered c:\scripts\python\notify.py"
                                timeout /t 2
                                start cmd /k "node-red"
                                exit
                                This ensures that node-red is called after pynodered is loaded, and also allows pynodered to load. Of course, you'll need to change the paths, as my stuff is in the c:\scripts\python directory

                                Comment

                                Working...
                                X