In this BLOG entry I want to share some of my automation that I have planned on getting working with my PDU. This example is showing one Edison reporting temperature to Home Assistant and then Home Assistant turning on and off an outlet that the fan is plugged into. Hard to read the temperature on the tablet, but as it climbs to over 80 degrees, it turns on the fan and when to goes back down to under 78 it will turn it off. I am simply using my finger to warm up the temperature sensor to over 80 degrees.
Here is how this is all done. Node-Red reads, converts, and reports the temperature via MQTT and Web Sockets (WS). Then Home Assistant reads and displays this value. Also I have automation setup to turn on and off the fan. Lets break down the parts.
Node-red
Here you can see the Temperature is being read, then formatted to Celsius and Fahrenheit. The sent back out. The conversion looks like this.
var retMsg = {}; var a = msg.payload; var B = 4275; var R = (1023.0/a - 1.0) * 100000.0; var tC = 1.0 / (Math.log(R/100000.0) / B + 1 /298.15) - 273.15; var tF = Math.round((tC * 9 / 5 + 32) * 100) / 100; retMsg.payload = { tempC: Math.round(tC * 100) /100, tempF: tF } return retMsg;
Then I publish to the MQTT channel and the WS. What goes out is JSON with both values in it.
Sensor in Home Assistant (HA)
Next I setup the sensor in HA. The tricky part is getting the value out of the object that I want to see. I would setup Fahrenheit for myself, but my Dad would like to see Celsius. Here is the sensor config:
- platform: mqtt state_topic: "office/temperature/status" name: "Office Temperature" qos: 0 unit_of_measurement: "°F" value_template: "{{ value_json.tempF }}"
and here is what it looks like in HA:
Click on it and I see:
You can see my history of doing tests of the fan. I have thought about taking ten samples, taking out the high and low and averaging the rest of the values to report a more steady temperature.
Automation in HA
Here is where the fun starts. Before I setup all eight outlets in HA. Now I plugged a fan into outlet 1, because when it gets hot in my office, it is nice to have a fan blowing on me. But who wants to think when we have computers to do that for us. So I setup two automation configurations. One turns on the fan during working hours if the temperature is reported at over 80 degrees and the fan is off, no since in telling it to turn on when it is on. The seconds turns off the fan if the fan is on and if the temperature goes below 78 degrees. On the off automation, there is no time constraint, because I want it to turn off when the room is cool. I might setup a third automation that turns off the fan after 10PM, because who needs it then and if I do need it, I can turn it on via HA!
Here is my ON automation:
:::::::::::::: fan_on.yaml :::::::::::::: alias: 'Turn on office fan' trigger: platform: numeric_state entity_id: sensor.office_temperature above: 80 condition: condition: and conditions: - condition: time after: '08:00:00' before: '17:00:00' weekday: - mon - tue - wed - thu - fri - condition: state entity_id: switch.tower_pdu_outlet1 state: 'off' action: service: switch.turn_on entity_id: switch.tower_pdu_outlet1
Here is of OFF automation
:::::::::::::: fan_off.yaml :::::::::::::: alias: 'Turn off office fan' trigger: platform: numeric_state entity_id: sensor.office_temperature below: 78 condition: condition: state entity_id: switch.tower_pdu_outlet1 state: 'on' action: service: switch.turn_off entity_id: switch.tower_pdu_outlet1
This was my main objective of the project. I still would like to do more with the LCD, but my mom's health problems and daughter's graduation, I might have to put some extras on hold for now. Before this would go in my tower, I would see a world where I would replace outlets with terminals or connectors to turn on and off 12V devices. And if this would stay at my desk, I would picture me making it into a PDU that is also a power supply with USB ports build in and replacing some outlets. Also using solid state relays for the outlets. I am having good fun with this project.
Top Comments