d_sellers1

Auto Lighting Payload handler

Feb 22nd, 2023
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var light_entity = "light.hallway"
  2.  
  3. var ha = global.get('homeassistant').homeAssistant
  4. var light_state = ha.states[light_entity].state
  5.  
  6. if (ha.states["input_boolean.automation_auto_hallway_lights"].state === "off") {
  7.     node.status({ fill: "red", shape: "dot", text: "Automation disabled" });
  8.     return
  9. }
  10.  
  11. if (msg.topic === "light") {
  12.     if (light_state === "on") {
  13.         node.status({fill:"green", shape:"dot", text: "Light turned on"});
  14.         msg.payload === "on";
  15.     }
  16.    
  17.     if (light_state === "off") {
  18.         node.status({fill:"red", shape:"dot", text: "Light turned off"})
  19.         msg.payload === "cancel";
  20.     }
  21. }
  22.  
  23. //Needs to be revised
  24. if (msg.topic === "door") {
  25.     if (light_state === "off") {
  26.         node.status({ fill: "green", shape: "dot", text: "Door opened" });
  27.         msg.payload === "on";
  28.     }
  29.  
  30.     if (light_state === "on") {
  31.         node.status({ fill: "red", shape: "dot", text: "Door closed" })
  32.         msg.payload === "cancel";
  33.     }
  34. }
  35.  
  36. if (msg.topic === "motion") {
  37.     if (msg.payload === "on" && light_state === "on") {
  38.         node.status({fill:"red", shape:"ring", text: "Motion while light on"});
  39.         msg.payload === "reset";
  40.     }
  41.     if (msg.payload === "on" && light_state === "off") {
  42.         node.status({fill:"green", shape:"ring", text: "Motion while light off"});
  43.         msg.payload === "on";
  44.     }
  45.     if (msg.payload === "off" && light_state === "off") {
  46.         node.status({fill:"red", shape:"ring", text: "Motion stopped with light off"});
  47.         return;
  48.     }
  49.     if (msg.payload === "off" && light_state === "on") {
  50.         node.status({fill:"red", shape:"ring", text: "Motion stopped while light on"});
  51.         return;
  52.     }
  53. }
  54.  
  55. return msg;
Advertisement
Add Comment
Please, Sign In to add comment