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

  • #31
    The above has some pre-requisites:
    1. In the flow, it is expecting a mqtt message like Notify/6=this is a test This would send "this is a test" for a duration of 6 seconds to be displayed
    2. Look in the change nodes - there is a property called msg.server - this is the IP of your firestick
    3. You can set the filename to whatever you want - I have it set to show the last image from the netcam homeseer plugin

    Comment


    • #32
      Originally posted by Furious View Post

      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
      I'm going to dive into this as soon as I get a chance, thanks!!

      Comment


      • #33
        Once you get node-red installed, install the amazon echo stuff, you can control so much with it

        Comment


        • #34
          Originally posted by Furious View Post
          Once you get node-red installed, install the amazon echo stuff, you can control so much with it
          I have experimented with the Echo stuff but I haven't put it to anything practical yet. I have the wemo stuff added in, that along with MQTT is way better than IFTTT.

          Comment

          Working...
          X