Indigo / Node-Red / Alexa

Posted on
Tue May 26, 2020 11:50 pm
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Indigo / Node-Red / Alexa

New Coolness.

Create a fake Motion sensor device, trigger via indigo action to run an Alexa routine!

How to:

Http in node: Get. URL = "/fakemotion1. name = "fakemotion1" -->. (Add a http response node after this node AND to the json node)
json node, Convert between JSON String & Object -->
switch == {"power":"on"} --> 1. {"power":"off"} -->2
Change node for each leg of the switch. (set message to "ON", set message to "OFF") respectively... Both change nodes funnel to one function node -->
Function node (translates to something Alexa understands)
Code: Select all
// Motion State
if (msg.payload == "ON") {
    return { "payload" : { "state" : { "motion" : "DETECTED" } }, "acknowledge" : true };
}
else if (msg.payload == "OFF") {
    return { "payload" : { "state" : { "motion" : "NOT_DETECTED" } }, "acknowledge" : true };
}

--> Alexa Smart home v3 state (select your fake motion detector you created.

on the indigo side.... action: execute embedded python: (substitute URL:Port with the url & port of your node red server:
Code: Select all
import requests
r = requests.get('http://192.168.1.10:1880/fakemotion1?power=on')
r.raise_for_status()


EDIT The above script will leave the fake detector in a "DETECTED" state forever. Add a second action with a delay to the same action with the same code, but use power=off. Example use: (All my kids bedrooms have the GE Motion light switch and a Amazon Flex. In my teenager's room, if motion is detected, it runs the above script which node-red sends to Alexa to then trigger a routine to play a fart sound.

Here is a picture of the node order. Your's will look a little different, unless your name is Bill also.
Attachments
FakeMotion.jpeg
FakeMotion.jpeg (132.33 KiB) Viewed 4539 times
Last edited by whmoorejr on Wed May 27, 2020 9:24 am, edited 1 time in total.

Bill
My Plugin: My People

Posted on
Wed May 27, 2020 2:00 am
siclark offline
Posts: 1960
Joined: Jun 13, 2017
Location: UK

Re: Indigo / Node-Red / Alexa

whmoorejr wrote:
Guest wrote:
whmoorejr wrote:
deleting the device from https://red.cb-net.co.uk/login and from Alexa then discovering it again?


Still no dice. Created a new flow for another fan.... "Set bedroom fan to Low".... Alexa Replies "I don't know how to set bedroom fan to that setting". The data doesn't make it past the echo (nothing happens from my collection of debug nodes.)
Have you tried set bedroom fan to 1?

Posted on
Wed May 27, 2020 7:57 am
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Indigo / Node-Red / Alexa

siclark wrote:
Have you tried set bedroom fan to 1?


"one" works, so does "dim", "decrease" and "increase". I get the same results on both of my fans. (3rd fan is on a wall switch... no speed control) All provide a msg.payload of 1 which process through the range node properly. From the input of others on this thread, I believe I have the only batch of echo devices in the world that don't recognize the command "Low".
Attachments
GetLow.jpeg
GetLow.jpeg (42.65 KiB) Viewed 4506 times

Bill
My Plugin: My People

Posted on
Thu Jun 04, 2020 12:38 pm
whmoorejr offline
User avatar
Posts: 762
Joined: Jan 15, 2013
Location: Houston, TX

Re: Indigo / Node-Red / Alexa

I'm now using the following Pallette Nodes:

node-red-contrib-alexa-smart-home (v0.4.66): My default node for communicating device to device between Alexa and Indigo.

node-red-dashboard (v.2.22.1) : It's for making a UI page, great for testing because you can easily create a button to run a flow which is my main use as I plink around with Node-red.

node-red-contrib-alexa-remote2 (v.3.10.0): This is my goto node for all other things Alexa. Great for creating announcements, sounds, launching routines, setting device volumes,

Bill
My Plugin: My People

Posted on
Sun Jun 14, 2020 10:28 am
madscientist offline
Posts: 121
Joined: Jan 05, 2007
Location: Ontario, Canada

Re: Indigo / Node-Red / Alexa

matt (support) wrote:
The macOS won't let any process that isn't running as root listen for incoming connections on port 80 (or other lower/system ports). Running it as root is a solution (and the only sol'n we have so far for port 80 access), albeit not the safest one.


I installed node-red on a raspberry pi that runs a pi-hole server. Initially, node-red would not connect to amazon-echo-hub because binding to port 80 is not permitted by a process not running as the root user. So I remapped port 80 to 8980 using iptables and it is now working just fine even through the process is not running as root. Here are the commands for the raspberry pi:

Code: Select all
sudo apt-get install iptables-persistent
sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
sudo iptables -A PREROUTING -t nat -i wlan0 -p tcp --dport 80 -j REDIRECT --to-port 8980
sudo netfilter-persistent save
sudo netfilter-persistent reload

I don't think Macs can run iptables, but perhaps pf can be used instead?

Posted on
Sun Jun 14, 2020 11:02 am
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Indigo / Node-Red / Alexa

There were a variety of attempts to do this by @autolog trying to get the Alexa-Hue Bridge plugin working with no success (though I don't recall the details). macOS is locked down very tightly which makes this kind of fakery very difficult. It may be possible though - we haven't researched it ourselves.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jun 14, 2020 11:18 am
siclark offline
Posts: 1960
Joined: Jun 13, 2017
Location: UK

Re: Indigo / Node-Red / Alexa

Hi.

You shouldn’t need to do any port mapping to make either node red Alexa solutions work.

That includes for recent devices on the latest firmware.

Where was it failing?

Simon

Posted on
Sun Jun 14, 2020 12:29 pm
madscientist offline
Posts: 121
Joined: Jan 05, 2007
Location: Ontario, Canada

Re: Indigo / Node-Red / Alexa

I started off using node-red-contrib-amazon-echo and it would not connect to amazon-echo-hub inputs without the use of port forwarding. However, I am now using node-red-contrib-alexa-smart-home and it does not require any sort of port forwarding.

Posted on
Sun Jun 14, 2020 2:12 pm
siclark offline
Posts: 1960
Joined: Jun 13, 2017
Location: UK

Re: Indigo / Node-Red / Alexa

That’s the more fully functioning setup so you’ll get more functionality from that anyway.

Posted on
Tue Jun 16, 2020 3:11 pm
madscientist offline
Posts: 121
Joined: Jan 05, 2007
Location: Ontario, Canada

Re: Indigo / Node-Red / Alexa

After a couple more days of playing around with node-red for Alexa-Indigo integration I am loving it! I have so much more control now, and it seems to be fast and reliable. I am using node-red-contrib-indigo along with node-red-contrib-alexa-home for local Alexa control (no cloud!) of all my lights (on/off and dimmable). I also use node-red-contrib-alexa-smart-home to control more complex devices such as my pool heater which is connected to Indigo via an EasyDAQ Relay Card and linked to an Indigo thermostat device. I can finally tell Alexa to set my pool heater to a specific temperature, or to simply increase or decrease the temperature. Prior to that I could only turn the pool heater on/off via voice commands, and had to reach for the Indigo app to dial in a particular temperature, like some sort of Neanderthal.

My next challenge is to get Alexa to tell me the current pool water temperature. I can read the voltage of my pool heater's built-in temperature probe from a connector block on the heater circuit board, which is wired to an analog input on a Phidgets 8/8/8 using Berkinet's Phidgets Plug-In for Indigo. An Indigo trigger updates a variable representing my pool temperature whenever a change to the Phidgets card input occurs. A formula then converts the voltage to a temperature for use within Indigo. So far so good. However, I have not been able to figure out how to connect this to Alexa via node-red. I am running a Mosquitto MQTT broker server and publishing the variable state to a topic using the MQTT Connector plug-in. How do I now configure node-red so that Alexa can read the temperature? I notice that node-red-contrib-alexa-home has a temperature probe device, but I haven't been to figure out how to use it. Any help would be appreciated.

Posted on
Tue Jun 16, 2020 3:21 pm
siclark offline
Posts: 1960
Joined: Jun 13, 2017
Location: UK

Re: Indigo / Node-Red / Alexa

Hi

I’m glad you are enjoying it. I ignored node-red for years thinking it didn’t offer anything.
Very useful until Matt and Jay give us native Alexa

I think, as it’s still on my to do list, you need to go to the device in red.cb-net.co.uk and set the device to report state.

Then in node-red to need to feed the temperature as a payload into the Alexa-smart-home-v3-state node.

It should be something like this

Code: Select all
 
msg {
    acknowledge: true,
    payload {
        state {
            "temperature": number
        }
    }
}

Posted on
Tue Jun 16, 2020 5:54 pm
madscientist offline
Posts: 121
Joined: Jan 05, 2007
Location: Ontario, Canada

Re: Indigo / Node-Red / Alexa

Yes, I managed to get the temperature value into the node, but when I say, "Alexa, what's my pool water temperature?", she says "Doesn't support that".

I created a Temperature Sensor device on red.cb-net.co.uk called "Pool water", and made sure that State Reporting was enabled. This is the node-red flow:

Screen Shot 2020-06-16 at 7.40.59 PM.png
Screen Shot 2020-06-16 at 7.40.59 PM.png (80.75 KiB) Viewed 4354 times


This is the code in the function node:

Code: Select all
var temperature = msg.payload;
return { "payload" : { "state" : { "temperature" : temperature } }, "acknowledge" : true };


The debug window shows that the alexa-smart-home-v3-state node has received the temperature state. I feel like I'm just missing some little detail to actually make this work.

Screen Shot 2020-06-16 at 7.41.13 PM.png
Screen Shot 2020-06-16 at 7.41.13 PM.png (74.29 KiB) Viewed 4354 times

Posted on
Wed Jun 17, 2020 3:13 am
siclark offline
Posts: 1960
Joined: Jun 13, 2017
Location: UK

Re: Indigo / Node-Red / Alexa

Hi,

Reminder that one should always RTFM. 20 mins playing with change nodes, when the documentation shows how to do it with the function node.

So its working for me.

This is my function code.

Code: Select all
var temperature = msg.payload.displayRawState;
return { "payload" : { "state" : { "temperature" : temperature } }, "acknowledge" : true };


and my flow.
Screenshot 2020-06-17 at 10.10.46.png
Screenshot 2020-06-17 at 10.10.46.png (151.57 KiB) Viewed 4330 times


Is your debug window the full message, as you are missing the acknowledge part from attached.

Also what value does Alexa give for the device in the app, rather than on voice? Mine was showing a default 22 until I passed it a value. Have you tried discovering the device again?

Posted on
Wed Jun 17, 2020 3:15 am
siclark offline
Posts: 1960
Joined: Jun 13, 2017
Location: UK

Re: Indigo / Node-Red / Alexa

This is genius, as I have pibeacon temperatures, or aqara zigbee temperature sensors in most rooms, I can now do this across the house.

Posted on
Wed Jun 17, 2020 8:53 am
madscientist offline
Posts: 121
Joined: Jan 05, 2007
Location: Ontario, Canada

Re: Indigo / Node-Red / Alexa

Thanks for your help siclark. No, the debug window wasn't the full message, but the full message did indeed contain "acknowledge: true", and matches the format in your screenshot. I notice that you are pulling the temperature value using an 'indigo get variable' node, whereas I was pulling mine directly from my local MQTT broker. So I changed my flow to match yours. It now looks like this:
Screen Shot 2020-06-17 at 10.24.59 AM.png
Screen Shot 2020-06-17 at 10.24.59 AM.png (71.08 KiB) Viewed 4304 times

This initially produced the same result where Alexa would say "Doesn't support that"

So I had another look at my device configuration on red.cb-net.co.uk and noticed that both the 'Celsius' and 'Farenheit' [sic] checkboxes were unchecked, even though I definitely checked the Fahrenheit box. It seems there's a bug on red.cb-net.co.uk that is causing the Fahrenheit setting to be forgotten. I tried deleting the temperature sensor device and creating a new one, and sure enough, when I navigated back to it later the Fahrenheit setting had again disappeared. As a workaround, I checked the Celsius box, and that one remains checked.

It didn't work initially, but before giving up I rebooted the Raspberry Pi that is running both node-red and my MQTT broker, and VOILA, it now works!

Who is online

Users browsing this forum: No registered users and 5 guests