Anyone here doing home automation?

Thanks Dave. Got Red-Node and Mqtt working on windows :slight_smile: Used nodejs to install red-node and windows install for windows.

This is the code i’m using, does the wifi onbaord allow it to operate as webserver and mqtt client\server or can i only do one?

Awesome switches…goign to but some to see how they work…want receiver are you using for switches.

            if (Program.client == null)
                        {
                            // create client instance 
                            Program.client = new MqttClient(IPAddress.Parse("10.0.13.181"));

                            // register to message received 
                            Program.client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

                            string clientId = Guid.NewGuid().ToString();
                            Program.client.Connect(clientId);




                        }
                        Program.client.Publish("/home/temperature/", Encoding.UTF8.GetBytes("33"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, true);

@ Dave Wondering if you can assist, have installed mqtt on my fez cobra 2 board but will not connect to my mqtt broker.

The broker is working as i have tested it using mqttlisten on my chrome browser.

The board successfully makes a wifi connection but fails on the command Program.client.Connect(clientId);//error

How are you connecting to the internet?

You don’t need a server running on your NETMF device when using MQTT. The MQTT broker on your PC handles all of this. Just make sure that the PC’s IP address is not assigned dynamically and your router always gives it the same one or your system will fail.

You simply subscribe to a topic and when that topic receives a publish by the MQTT server, it will push the message to the receiver and then callback gets called and you can then handle that message. It’s a bit like push messages or push email. You remain connected to the MQTT server and this allows it to send you any messages you are subscribed to. There is very little overhead.

Once you see how this all works and how easy it is to send and receive without any polling, you will quickly get it all working.

For example, I have a module connected to a FAN in my front room. It is subscribed to the topic frontfan/toesp so once my Node-red sends a publish to frontfan/toesp with payload {out16:1}, the fan switches on. By sending {out16:0} it switches off. It’s very fast and virtually no delays that you can observe.

If I press a button on the FAN controller, it sends a topic frontfan/toesp/trigger14 with payload 0 for down and 1 for up. Node-red is subscribed to this and responds by sending a publish back to the fan as before. Even though the button doesn’t control the device directly, the speed of MQTT makes it appear as if it was done locally.

Hope this makes sense?

Make sense, i understand the protocol, but trying to get the client working on my fez cobra 2 with builtin wifi.

This is the code i am using to publish data, but it fails…

                   if (Program.client == null)
                        {
                            try
                            {


                                // create client instance 
                                Program.client = new MqttClient(IPAddress.Parse("10.0.13.181"));

                                // register to message received 
                                // Program.client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

                                string clientId = Guid.NewGuid().ToString();
                                Program.client.Connect(clientId);
                            }
                            catch (Exception ex)
                            {
                                Utils.Logit(LoggingLevel.error, ex.ToString());
                            }
                        }
                        Program.client.Publish("/home/temperature/", Encoding.UTF8.GetBytes("33"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, true);

How do you monitor this? What do you mean by fail? Is there an error?

Which library are you using? I can give it a try on a G120 with WiFi.

One thing I don’t see is how you setup the PORT that MQTT broker is listening on as part of your client connection? Most of the code I’ve seen is using 1883.

Does your MQTT broker on the PC have a command line to subscribe to messages? For me I tried the following with my Mosquitto broker and it worked but that is on Debian.

mosquitto_sub -t /home/temperature

and then use this to send 33 and it appears in the subscribe window.

mosquitto_pub -t /home/temperature -m 33

Thanks Dave , got it going?

Stupid me, didn’t realise that the vpn on my computer is not reflected on the board internet connection.

Have setup node-red and that pretty cool but do see how it could get pretty messy very quickly in the future.

Thanks for your response :slight_smile:

Good stuff.

Mine became messy too but I have since started to clean it up. You can have many flow tabs as you need so simply create one for each room. I have one for each room plus an admin one, Alexa flow, and one for auto functions. Makes it easier to keep track of things. When I had all of the autos on the same flow as each room it was a mess.

Thanks Dave…its an exciting technology…those powerless switch seem awesome…same company has powerless temperature ones also

@ Dave McLaughlin - What oenocean trasnceiver are you using for the switches? Do you need to program them or transmit the data to e board or other mcu?

I designed my own housing to fit over the existing switches. The rockers are supplied as STEP models from Enocean.

To use the modules, you simply add the Enocean Node-red module and the input is a serial port that this is connected to. There is a direct fit module for the Pi but you could use the USB modules with a PC. It appears as a serial port.

Then all you do is handle the payload which has the button ID, rocker A or B and state of 0 or 1 for top and button switches. I use switch nodes and look for msg.ID, msg.rocker and msg.state. See attached flow.

I’ll post up a bit on my blog tomorrow showing how this is done.

1 Like

Where do i get a Alexa from? I don’t think its available in Australia yet? Is this the Amazon Voice Service hardware?

Yip. To get it you would need a friendly US based friend to order one and ship it onward to you. This is what I had to do. It works but some things are missing but not enough that it won’t work. If you want to play music, make sure you can sign up to Amazon Prime first otherwise that part won’t work. My daughter loves that bit but means I have to put up with her choice of music sometimes. :slight_smile:

Another option is to use the Alexa Voice Service on a Raspberry Pi. Only downside is that it doesn’t have a wake word and needs a button to start recognition so you would have to code that yourself.

Another option is ReSpeaker from Seeed Studio.

This mic array from them could be used with the Raspberry Pi to give you far field voice recognition.

Note that this is pre-order for end of Nov.

That looks like some advanced technology…is voice recognition on the chip or has specific firmware?

Can you get a desktop voice control, that would be useful, my computer is always on so why not!

Wow, another Aussie, and I didn’t even realise !

I can now say that I have done some home automation. Not quite what you guy are talking about in the thread but something none the less.

I got an amazon dash button to control a wifi outlet ;D

Question about the buttons. Although they use a battery, how long would they last if used for switching things on and off? Say 5-10 presses per day?

If they can output an HTTP request or TCP/IP etc, Node-red can capture this and be used to control anything.

@ Dave McLaughlin -

Dave, I have node red running on my MultiConnect LoRaWAN gateway.

What are you running it on? Please explain more about what you are talking about.
Thx.

Hi Terrence,

I am running it on a Pi3 with Mosquitto MQTT broker. I also have the Amazon Echo HABridge running on it to allow the Echo to control devices by voice commands. These are sent as HTTP requests.

Node-red can be setup to receive HTTP and I use the following to switch a lamp on from the Echo by simply asking “Alexa, turn on left lamp” and then I receive this into Node-red. There is a corresponding one for off with value=0

http://192.168.1.146:1880/echo/?request=control&ref=LeftLamp&value=1

The Node-red HTTP receiver is listing for /echo URL messages. I then parse these checking msg.ref and msg.value. Eg. this function has 6 outputs. The first is simply sent back to the Echo as a reply. The HABridge for the timing being doesn’t use this. It just needs this as a confirmation of handling the message.


var who = msg.payload.ref;

if(who == "TVLamp")
{
    return [msg, msg, null, null, null, null];
}
if(who == "TableLamp")
{
    return [msg, null, msg, null, null, null];
}
if(who == "ComputerLamp")
{
    return [msg, null, null, msg, null, null];
}
if(who == "KitchenLamp")
{
    return [msg, null, null, null, msg, null];
}
if(who == "Bedroom1Light")
{
    return [msg, null, null, null, null, msg];
}
return [null, null, null, null, null, null];

Hope this makes sense?

1 Like

@ Dave McLaughlin - Yes I understand.

Why NodeRed instead of an MVC website are API site in the RPI that will accept the posted data? Is setting up NR easier or what?..trying to figure out if I want to include it in my tool belt.

Thanks.

I thought you said WIFE there. Wondered how you’d managed to get magic?

1 Like