I hope you enjoyed the Microsoft Developer Cloud Summit today! Thank you very much for attending my session: Automating your home or office with IoT Central and Power Apps” It was a lot of information in 30 min, so here’s the content, resources and source code.
This whole session was done using Home Automation devices combined with OBS. Camera Scene changes were controlled with a standard home remote control. So automation doesn’t have to be traditional garage doors or lighting, you can control you PC life too! 😎 Controlling your OBS Scenes with a Home Automation device
The 433 Mhz Bridge when it detects a signal, it publishes a message with it’s contents via MQTT. These will have codes attached to them and in the case of a remote, that code / data that is sent via the message payload translates to the button pressed. You can “train” your solution with the remotes you have. These can be standard house-hold remotes.
The switch statements routes the flow based on the button data to a specific function.
The function sends a message with the “scene-name” with the parameter of the scene created in OBS.
For additional commands refer to the protocol document:
I control a few devices from the Internet, but I don’t want all devices exposed and connected to IoT Central. One solution is to build a gateway locally which routes request messages to switch things on or off to the correct device locally.
In this post we will look at how to send commands from IoT Central and route them using Node-RED to the automation device via MQTT.
This architure uses Node-RED as a gateway, and then uses Eclipse Mosquito as a MQTT server. The Grow Light and Air Conditioner in the diagram is an off the shelf Sonoff POW-R2 device flashed with Tasmota.
With Node-RED you can visually map the flow / sequence of events. Node-RED supports Azure IoT Hubs and Azure IoT Central, so it’s perfect for this job to do quickly and easily without having to write code.
In Azure IoT Central we have a single device linked with a command. The command accepts a parameter, which will be the device name / topic name on the local MQTT server.
The diagram above shows the command with the parameter.
The Node-RED Azure component supports Direct Methods. These are commands that you can directly invoke on a device. In this case, the device is the gateway itself created within Node-RED.
It supports two methods (as per Azure IoT Central template)
With a Node-Red switch statement we can controll the flow with whichever method name was invoked from IoT Central.
If it’s the “DeviceOn” flow, then the device parameter name (payload) is used to build up the topic for the Sonoff device via MQTT. The payload of the message will be “on”.
If it’s the “DeviceOff” flow, then the device parameter name (payload) is used to build up the topic for the Sonoff device via MQTT. The payload of the message will be “off”.
Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 5.0, 3.1.1 and 3.1. Mosquitto is lightweight and is suitable for use on all devices from low power single board computers to full servers.
The MQTT protocol provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for Internet of Things messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers.
Running Mosquitto is easiest in a Docker container. This is really easy to set up.