Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var light_entity = "light.hallway"
- var ha = global.get('homeassistant').homeAssistant
- var light_state = ha.states[light_entity].state
- if (ha.states["input_boolean.automation_auto_hallway_lights"].state === "off") {
- node.status({ fill: "red", shape: "dot", text: "Automation disabled" });
- return
- }
- if (msg.topic === "light") {
- if (light_state === "on") {
- node.status({fill:"green", shape:"dot", text: "Light turned on"});
- msg.payload === "on";
- }
- if (light_state === "off") {
- node.status({fill:"red", shape:"dot", text: "Light turned off"})
- msg.payload === "cancel";
- }
- }
- //Needs to be revised
- if (msg.topic === "door") {
- if (light_state === "off") {
- node.status({ fill: "green", shape: "dot", text: "Door opened" });
- msg.payload === "on";
- }
- if (light_state === "on") {
- node.status({ fill: "red", shape: "dot", text: "Door closed" })
- msg.payload === "cancel";
- }
- }
- if (msg.topic === "motion") {
- if (msg.payload === "on" && light_state === "on") {
- node.status({fill:"red", shape:"ring", text: "Motion while light on"});
- msg.payload === "reset";
- }
- if (msg.payload === "on" && light_state === "off") {
- node.status({fill:"green", shape:"ring", text: "Motion while light off"});
- msg.payload === "on";
- }
- if (msg.payload === "off" && light_state === "off") {
- node.status({fill:"red", shape:"ring", text: "Motion stopped with light off"});
- return;
- }
- if (msg.payload === "off" && light_state === "on") {
- node.status({fill:"red", shape:"ring", text: "Motion stopped while light on"});
- return;
- }
- }
- return msg;
Advertisement
Add Comment
Please, Sign In to add comment