One of my goals was to integrate this from Home Assistant. Home Assistant (HASS) is open-source home automation package written in Python. Check it out. It can talk to several devices using multiple protocols. I use mine to automate my lights to turn on and off in the kitchen (under counter that are on all night) and to turn on my wife's coffee machine (not working now, because the Belkin WeMo Switch is broke). Since HASS currently has access to many things in my house, it would be nice that my PDU project would play with it. I have modified my Node-Red setup on my Edison to send out and receive proper MQTT to integrate right into HASS. Also in this update, I will show you the starts of the new web interface I am designing.
Demo Of This Working
Home Assistant Config
Here is one outlet configured. I have 7 more files just like it.
:::::::::::::: switches/mqtt/toweroulet01.yaml :::::::::::::: platform: mqtt name: "Tower PDU Outlet1" state_topic: "tower/outlet0001/status" command_topic: "tower/outlet0001/control" qos: 0
My Tower Power Group:
Tower:
name: "Tower"
entities:
- switch.Tower_PDU_Outlet1
- switch.Tower_PDU_Outlet2
- switch.Tower_PDU_Outlet3
- switch.Tower_PDU_Outlet4
- switch.Tower_PDU_Outlet5
- switch.Tower_PDU_Outlet6
- switch.Tower_PDU_Outlet7
- switch.Tower_PDU_Outlet8
And a view so that the group can have it's own tab
Tower_view:
view: yes
name: "Tower Power"
entities: group.Tower
Node-Red MQTT Message
Next modification was to have Node-Red MQTT jive with HASS. HASS expects to turn on and off outlets with the ON and OFF commands in the MQTT message. Now you can customized this, but why not play nice. I could modify HASS to send a 1 for ON and a 0 for OFF with the payload commands for ON and OFF. I chose to have Node-Red flows that talk HASS' lingo. Here is a sample of each sending a status and receiving a command.
Here is receiving the command. This one if for MQTT topic "tower/outlet0008/control", then the OnOffConversion takes the payload and converts it to a 0 or 1 as needed. Simple, but repetitive in Node-Red.
And on the status update side:
With the OnOffConversion code looking like this.
var state = "OFF"
if (msg.payload == "1")
state = "ON";
var nMsg = { payload: state };
return nMsg;


Top Comments