GUIDE- Remote Computer Power Management For Your Smart Home

Everything about esp8266 and more.

Moderator: leecollings

Post Reply
wou5er
Posts: 12
Joined: Thursday 01 March 2018 22:23
Target OS: -
Domoticz version:
Contact:

GUIDE- Remote Computer Power Management For Your Smart Home

Post by wou5er »

First of most of the work is not my work but i went ahead to make it compatible with domoticz in using MQTT and NodeRed. Also most coding credits go to some one else who i dont know on the forum...

So this thing came on my way put asside for a long time cause i didn't want to use mqtt for a long time...Now after having everything automated I need to have this, remotely power pc on and off.. without WOL.

I found this:
https://github.com/thehookup/MQTT_Computer_Power

I expect you know how to flash an ESP with arduino IDE.

Take the code from the github fill in your credentials and flash it.
Electric scheme is also on the github.

In node red import this code and make sure your topics are right.

Code: Select all

[{"id":"360fb868.958e68","type":"tab","label":"Wireless PowerButton PC","disabled":false,"info":""},{"id":"48be31a1.da135","type":"mqtt in","z":"360fb868.958e68","name":"state/PC","topic":"state/PC","qos":"0","datatype":"auto","broker":"5f164b7c.29b854","x":460,"y":280,"wires":[["4ee2609c.d7e81","b731aeb0.631ff"]]},{"id":"484f346e.b4b68c","type":"mqtt out","z":"360fb868.958e68","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"5f164b7c.29b854","x":1050,"y":280,"wires":[]},{"id":"4ee2609c.d7e81","type":"change","z":"360fb868.958e68","name":"PC Power Status","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"command\": \"switchlight\", \"idx\": 161, \"switchcmd\": \"Toggle\" }","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":260,"wires":[["484f346e.b4b68c","a1de914f.45af6"]]},{"id":"a1de914f.45af6","type":"debug","z":"360fb868.958e68","name":"To domoticz","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1050,"y":180,"wires":[]},{"id":"b731aeb0.631ff","type":"debug","z":"360fb868.958e68","name":"From device","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":180,"wires":[]},{"id":"2da78677.63be1a","type":"mqtt in","z":"360fb868.958e68","name":"domoticz/out","topic":"domoticz/out","qos":"2","datatype":"auto","broker":"5f164b7c.29b854","x":470,"y":440,"wires":[["e7ff2efa.ea97c","8a53d4a9.81e858"]]},{"id":"e7ff2efa.ea97c","type":"debug","z":"360fb868.958e68","name":"From Domoticz","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":600,"wires":[]},{"id":"55a379f.0099c88","type":"mqtt out","z":"360fb868.958e68","name":"commands/PC","topic":"commands/PC","qos":"","retain":"","broker":"5f164b7c.29b854","x":1060,"y":440,"wires":[]},{"id":"db8f9272.7a64f","type":"debug","z":"360fb868.958e68","name":"To device","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1040,"y":600,"wires":[]},{"id":"8a53d4a9.81e858","type":"function","z":"360fb868.958e68","name":"make Wemos D1 Payload","func":"var msgIn = JSON.parse(msg.payload);\nvar msgOut = null;\nvar idx = msgIn.idx;\n// hier gaan we de status bewaard in ander deel van de flow ophalen\n// als we die niet vinden, nemen we default \"OFF\"\nvar currentStatus = context.flow.currentStatus || \"OFF\";\n\nif (idx == 162) { // de Domoticz knop index\n    node.warn(msgIn);\n    var wantedStatusFromDomoticz = msgIn.svalue1;\n    var wantedStatusForWemos;\n    node.warn(wantedStatusFromDomoticz);\n\n    switch(wantedStatusFromDomoticz) {\n    case '20':\n        wantedStatusForWemos = \"OFF\"\n        break;\n    case '30':\n        wantedStatusForWemos = \"FORCE OFF\"\n        break;\n    default:\n        wantedStatusForWemos = \"ON\"\n    }\n    \n    node.warn(wantedStatusForWemos);\n    \n    if (currentStatus != wantedStatusForWemos || wantedStatusForWemos == \"FORCE OFF\") {\n        msgOut = {};\n        msgOut.topic = \"commands/PC\";\n        msgOut.payload = wantedStatusForWemos;\n        node.warn(msgOut);\n    }\n\n}\n// als de message niet over de juiste knop gaat is msgOut null,\n// dwz geen waarde.\n// op die manier trigger je zowiezo niets en heb je ook geen 2\n// uitgangen (return) in jouw functie.\nreturn msgOut;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":770,"y":440,"wires":[["55a379f.0099c88","db8f9272.7a64f"]]},{"id":"5f164b7c.29b854","type":"mqtt-broker","name":"localhost","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
I'm not responsible for any damages or broken parts after using this guide.
You have been warned.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests