Advertisement
DeanoX

NSPanel ESPHome yaml

Jan 11th, 2022
2,303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 25.78 KB | None | 0 0
  1. esphome:
  2.   name: esp-nsp01
  3.   comment: Sonoff NSPanel 01 - Location TBA
  4.   on_boot:
  5.     priority: 1000
  6.     then:
  7.        - delay: 8s
  8. #       - script.execute: nspanel_init
  9.        - delay: 5s
  10. #       - script.execute: nspanel_weather
  11.        
  12.  
  13. esp32:
  14.   board: esp32dev
  15.  
  16. wifi:
  17.   ssid: 'xxxx'
  18.   password: 'xxxx'
  19.   manual_ip:
  20.     static_ip: 192.168.1.158
  21.     gateway: 192.168.1.254
  22.     subnet: 255.255.255.0
  23.     dns1: 8.8.8.8
  24.     dns2: 192.168.1.254
  25.  
  26. time:
  27.   - platform: homeassistant
  28.     id: homeassistant_time
  29.  
  30. api:
  31.   id: api_server
  32.  
  33. logger:
  34.   on_message:
  35.     level: DEBUG
  36.     then:
  37.       lambda: |-
  38.         std::string message1 = message;
  39.         std::size_t pos1 = message1.find("PAYLOAD");
  40.         if (pos1 != std::string::npos)
  41.           {
  42.           id(nsp_return_message).publish_state(message);
  43.           }
  44.  
  45. ota:
  46. web_server:
  47. http_request:
  48.   useragent: esphome/device
  49.   timeout: 5s
  50.  
  51. substitutions:
  52. # Unique ID for Sensors.
  53.   switch_id: "nsp01"
  54.   friendly_name: "NSPanel 01"
  55.  
  56. uart:
  57.   tx_pin: 16
  58.   rx_pin: 17
  59.   baud_rate: 115200
  60.  
  61. external_components:
  62. #  - source: github://pr#2702
  63. #    components: ["nspanel"]
  64.   - source:
  65.       type: local
  66.       path: components
  67.     components: ["nspanel"]
  68.  
  69. globals:
  70.    - id: g_rgb_r
  71.      type: int
  72.      restore_value: no
  73.      initial_value: '0'
  74.    - id: g_rgb_g
  75.      type: int
  76.      restore_value: no
  77.      initial_value: '0'
  78.    - id: g_rgb_b
  79.      type: int
  80.      restore_value: no
  81.      initial_value: '0'
  82.    - id: g_brightness
  83.      type: int
  84.      restore_value: no
  85.      initial_value: '0'
  86.    - id: g_temperature
  87.      type: int
  88.      restore_value: no
  89.      initial_value: '0'
  90.  
  91. interval:
  92.   - interval: 60min
  93.     then:
  94.        - script.execute: nspanel_weather
  95.  
  96. nspanel:
  97.   id: nspanel1
  98.   time_id: homeassistant_time
  99.   temperature: ${switch_id}_temperature
  100.   eco_mode_switch: ${switch_id}_eco_mode
  101.   screen_power_switch: ${switch_id}_screen_power
  102.   relays:
  103.    - ${switch_id}_relay_1
  104.     - ${switch_id}_relay_2
  105. #  widgets:
  106. #    - type: scene
  107. #      name: S1
  108. #      on_click:
  109. #        - logger.log: "S1"
  110. #    - type: scene
  111. #      name: S2
  112. #      on_click:
  113. #        - logger.log: "S2"
  114. #    - type: scene
  115. #      name: S3
  116. #      on_click:
  117. #        - logger.log: "S3"
  118. #    - type: scene
  119. #      name: S4
  120. #      on_click:
  121. #        - logger.log: "S4"
  122. #    - type: scene
  123. #      name: S5
  124. #      on_click:
  125. #        - logger.log: "S5"
  126. #    - type: scene
  127. #      name: S6
  128. #      on_click:
  129. #        - logger.log: "S6"
  130. #    - type: scene
  131. #      name: S7
  132. #      on_click:
  133. #        - logger.log: "S7"
  134. #    - type: scene
  135. #      name: S8
  136. #      on_click:
  137. #        - logger.log: "S8"
  138.  
  139.    
  140. binary_sensor:
  141.   - platform: gpio
  142.     id: ${switch_id}_button_1
  143.     name: Left Button
  144.     pin:
  145.       number: 14
  146.       inverted: true
  147.     on_click:
  148.       - switch.toggle: ${switch_id}_relay_1
  149.       - script.execute: nspanel_weather
  150.  
  151.   - platform: gpio
  152.     id: ${switch_id}_button_2
  153.     name: Right Button
  154.     pin:
  155.       number: 27
  156.       inverted: true
  157.     on_click:
  158.       - switch.toggle: ${switch_id}_relay_2
  159.  
  160.   - platform: homeassistant
  161.     id: dim_09_light
  162.     entity_id: light.dim_09_light
  163.     on_press:
  164.       then:
  165.         - lambda: 'id(nspanel1).send_json_command_(0x86,"{\"id\":\"light7\",\"params\":{\"switch\":\"on\"}}");'
  166.     on_release:
  167.       then:
  168.         - lambda: 'id(nspanel1).send_json_command_(0x86,"{\"id\":\"light7\",\"params\":{\"switch\":\"off\"}}");'
  169.   - platform: homeassistant
  170.     id: wled_test_light
  171.     entity_id: light.wled_test
  172.     on_press:
  173.       then:
  174.         - lambda: 'id(nspanel1).send_json_command_(0x86,"{\"id\":\"wled_test\",\"params\":{\"switch\":\"on\"}}");'
  175.     on_release:
  176.       then:
  177.         - lambda: 'id(nspanel1).send_json_command_(0x86,"{\"id\":\"wled_test\",\"params\":{\"switch\":\"off\"}}");'
  178.   - platform: homeassistant
  179.     id: plug_09_switch
  180.     entity_id: switch.plug_09_relay_1
  181.     on_press:
  182.       then:
  183.         - lambda: 'id(nspanel1).send_json_command_(0x86,"{\"id\":\"plug_09\",\"params\":{\"switch\":\"on\"}}");'
  184.     on_release:
  185.       then:
  186.         - lambda: 'id(nspanel1).send_json_command_(0x86,"{\"id\":\"plug_09\",\"params\":{\"switch\":\"off\"}}");'
  187. output:
  188.   - platform: ledc
  189.     id: ${switch_id}_buzzer_out
  190.     pin:
  191.       number: 21
  192.  
  193. text_sensor:
  194.   - platform: template
  195.     name: "NSPanel Return String (Log)"
  196.     internal: true
  197.     id: nsp_return_message
  198.     lambda: |-
  199.       return {};
  200.     update_interval: 60s
  201.     #Verify JSON content in Log message, split and update Type/JSON text sensores
  202.     on_value:
  203.       then:
  204.         - lambda: |-
  205.             std::string message = id(nsp_return_message).state;
  206.             std::size_t pos1 = message.find("Type");
  207.             std::size_t pos2 = message.find(" PAYLOAD");
  208.             std::size_t pos3 = message.find(" RAW");
  209.             if (pos1 != std::string::npos && pos2 != std::string::npos && pos3 != std::string::npos)
  210.               {
  211.               id(nsp_return_type).publish_state(message.substr(pos1+5,pos2-pos1-5));
  212.               id(nsp_return_json).publish_state(message.substr(pos2+9,pos3-pos2-9));
  213.               }
  214.  
  215.   - platform: template
  216.     name: "NSPanel Return Type"
  217.     id: nsp_return_type
  218.     lambda: |-
  219.       return {};
  220.     update_interval: 60s
  221.   - platform: template
  222.     name: "NSPanel Return JSON"
  223.     id: nsp_return_json
  224.     lambda: |-
  225.       return {};
  226.     update_interval: 60s
  227.     # section to take JSON messages from NSPanel (GUI button presses) and update HA
  228.     on_value:
  229.       then:
  230.         - logger.log: "JSON text Updated"
  231.         - lambda: |-
  232.             std::string message = id(nsp_return_json).state;
  233.             std::string type = id(nsp_return_type).state;
  234.             std::string rgb_r,rgb_g,rgb_b;
  235.             float brightness;
  236.             DynamicJsonBuffer doc(2000);
  237.             JsonObject& root = doc.parseObject(message);
  238.             if (type == "0x86") {
  239.               // Device Type Message
  240.                 // Device ID Light 7
  241.                 if (root.containsKey("id") && strcasecmp(root["id"], "light7") == 0) {  
  242.                   JsonObject& params = root["params"];
  243.                   if (params.containsKey("switch")) {
  244.                     if(params["switch"] == "on") {
  245.                       id(ha_service_name).publish_state("light.turn_on");
  246.                       id(ha_service_entityid).publish_state("light.dim_09_light");
  247.                     }
  248.                     if(params["switch"] == "off") {
  249.                       id(ha_service_name).publish_state("light.turn_off");
  250.                       id(ha_service_entityid).publish_state("light.dim_09_light");
  251.                     }
  252.                     id(ha_service1).execute();
  253.                   }
  254.                   else if(params.containsKey("white")) {
  255.                     JsonObject& white = params["white"];
  256.                     id(ha_service_name).publish_state("light.turn_on");
  257.                     id(ha_service_entityid).publish_state("light.dim_09_light");
  258.                     id(g_brightness) = int(white["br"].as<float>() / 100 * 255);
  259.                     id(text_g_brightness).publish_state(to_string(id(g_brightness)));
  260.                     id(ha_service2).execute();
  261.                   }
  262.                 }
  263.                 if (root.containsKey("id") && strcasecmp(root["id"], "wled_test") == 0) {  
  264.                   JsonObject& params = root["params"];
  265.                   if (params.containsKey("bright")) {
  266.                     id(ha_service_name).publish_state("script.set_light_on_rgb");
  267.                     id(ha_service_entityid).publish_state("light.wled_test");
  268.                     id(g_brightness) = int(params["bright"].as<float>() / 100 * 255);
  269.                     id(text_g_brightness).publish_state(to_string(id(g_brightness)));
  270.                     id(g_rgb_r) = params["colorR"];
  271.                     id(g_rgb_g) = params["colorG"];
  272.                     id(g_rgb_b) = params["colorB"];
  273.                     id(ha_service3).execute();
  274.                   }
  275.                   else if (params.containsKey("switch")) {
  276.                     if(params["switch"] == "on") {
  277.                       id(ha_service_name).publish_state("light.turn_on");
  278.                       id(ha_service_entityid).publish_state("light.wled_test");
  279.                       id(ha_service1).execute();
  280.                       }
  281.                     else if(params["switch"] == "off") {
  282.                       id(ha_service_name).publish_state("light.turn_off");
  283.                       id(ha_service_entityid).publish_state("light.wled_test");
  284.                       id(ha_service1).execute();
  285.                     }
  286.                   }
  287.                 }
  288.                 // Device ID Plug_09
  289.                 if (root.containsKey("id") && strcasecmp(root["id"], "plug_09") == 0) {  
  290.                   JsonObject& params = root["params"];
  291.                   if (params.containsKey("switch")) {
  292.                     if(params["switch"] == "on") {
  293.                       id(ha_service_name).publish_state("switch.turn_on");
  294.                       id(ha_service_entityid).publish_state("switch.plug_09_relay_1");
  295.                     }
  296.                     if(params["switch"] == "off") {
  297.                       id(ha_service_name).publish_state("switch.turn_off");
  298.                       id(ha_service_entityid).publish_state("switch.plug_09_relay_1");
  299.                     }
  300.                     id(ha_service1).execute();
  301.                   }
  302.                 }
  303.             } else if (type == "0x84") {
  304.                // Thermostat Messages
  305.                if (root.containsKey("ATCEnable") && root["ATCEnable"] == 0) {
  306.                  id(ha_service_name).publish_state("climate.turn_off");
  307.                  id(ha_service_entityid).publish_state("climate.shed");
  308.                  id(ha_service1).execute();
  309.                }
  310.                else if (root.containsKey("ATCEnable") && root["ATCEnable"] == 1) {
  311.                  id(ha_service_name).publish_state("climate.turn_on");
  312.                  id(ha_service_entityid).publish_state("climate.shed");
  313.                  id(ha_service1).execute();
  314.                }
  315.                if (root.containsKey("ATCExpect0")) {
  316.                  id(ha_service_name).publish_state("climate.set_temperature");
  317.                  id(ha_service_entityid).publish_state("climate.shed");
  318.                  id(g_temperature) = root["ATCExpect0"];
  319.                  if (id(g_temperature) != 0) { id(ha_service4).execute();}
  320.                }
  321.             }
  322.  
  323.   - platform: template
  324.     name: "HA Service Name"
  325.     id: ha_service_name
  326.     lambda: |-
  327.       return {};
  328.     update_interval: 60s
  329.   - platform: template
  330.     name: "HA Service Entity"
  331.     id: ha_service_entityid
  332.     lambda: |-
  333.       return {};
  334.     update_interval: 60s
  335.   - platform: template
  336.     name: "g_brightness"
  337.     id: "text_g_brightness"
  338.     lambda: |-
  339.       return {};
  340.     update_interval: 60s  
  341.   - platform: homeassistant
  342.     name: "HA wled_test RGB"
  343.     id: wled_test_rgb
  344.     entity_id: light.wled_test
  345.     attribute: rgb_color
  346.     internal: false
  347.     on_value:
  348.       then:
  349.         - script.execute: ha_wled_test_update
  350.   - platform: homeassistant
  351.     id: climate_state
  352.     name: "Climate State"
  353.     entity_id: climate.shed
  354.     internal: false
  355.     on_value:
  356.       then:
  357.         - lambda: |-
  358.             if (id(climate_state).state == "heat") {
  359.              id(nspanel1).send_json_command_(0x84,"{\"ATCEnable\":1}");
  360.             } else {
  361.              id(nspanel1).send_json_command_(0x84,"{\"ATCEnable\":0}");
  362.             }
  363.  
  364. script:
  365.  # Script to trigger basic HA Service with Service Name + Entity
  366.   # Service + Entity_id
  367.   - id: ha_service1
  368.     then:
  369.       - logger.log: "HA Service Script 1 Called"
  370.       - homeassistant.service:
  371.           service: !lambda return id(ha_service_name).state;
  372.           data:
  373.             entity_id: !lambda return id(ha_service_entityid).state;
  374.   # Service + Entity_id + Brightness
  375.   - id: ha_service2
  376.     then:
  377.       - logger.log: "HA Service Script 2 Called"
  378.       - homeassistant.service:
  379.           service: !lambda return id(ha_service_name).state;
  380.           data:
  381.             entity_id: !lambda return id(ha_service_entityid).state;
  382.             brightness: !lambda 'return id(g_brightness);'
  383.   # Service + Entity_id + Brightness + RGB
  384.   - id: ha_service3
  385.     then:
  386.       - logger.log: "HA Service Script 3 Called"
  387.       - homeassistant.service:
  388.           service: !lambda return id(ha_service_name).state;
  389.           data:
  390.             entity_name: !lambda 'return id(ha_service_entityid).state;'
  391.             brightness: !lambda 'return id(g_brightness);'
  392.             red: !lambda 'return to_string(id(g_rgb_r));'
  393.             green: !lambda 'return to_string(id(g_rgb_g));'
  394.             blue: !lambda 'return to_string(id(g_rgb_b));'
  395.   # Service + Entity_id + Temp (Climate Only)
  396.   - id: ha_service4
  397.     then:
  398.       - logger.log: "HA Service Script 4 Called"
  399.       - homeassistant.service:
  400.           service: !lambda return id(ha_service_name).state;
  401.           data:
  402.             entity_id: !lambda return id(ha_service_entityid).state;
  403.             temperature: !lambda 'return to_string(id(g_temperature));'
  404.             hvac_mode: "heat"
  405.   - id: ha_dim_09_light_update
  406.     then:
  407.       - lambda: |-
  408.           if (id(dim_09_light).state) {
  409.             int i_brightness = int(id(dim_09_light_bright).state / 255 * 100);
  410.             id(nspanel1).send_json_command_(0x86,"{\"id\":\"light7\",\"params\":{\"switch\":\"on\",\"ltype\":\"white\",\"white\":{\"br\":" + to_string(i_brightness) + "}}}");
  411.           } else {
  412.             id(nspanel1).send_json_command_(0x86,"{\"id\":\"light7\",\"params\":{\"switch\":\"off\"}}");
  413.           }
  414.  
  415.   - id: ha_wled_test_update
  416.     then:
  417.       - lambda: |-
  418.           if (id(wled_test_light).state) {
  419.             int i_brightness = int(id(wled_test_bright).state / 255 * 100);
  420.             std::string s = id(wled_test_rgb).state;
  421.             int p1 = s.find(",");
  422.             int p2 = s.find(",",p1+1);
  423.             std::string r = s.substr(1, p1-1).erase(0,s.find_first_not_of(" "));
  424.             std::string g = s.substr(p1+2,p2-p1-2).erase(0,s.find_first_not_of(" "));
  425.             std::string b = s.substr(p2+2,s.length()-2).erase(0,s.find_first_not_of(" "));
  426.             id(nspanel1).send_json_command_(0x86,"{\"id\":\"wled_test\",\"params\":{\"switch\":\"on\",\"light_type\":1,\"mode\":1,\"bright\":" + to_string(i_brightness) + ",\"colorR\":" + to_string(r) + ",\"colorG\":" + to_string(g) + ",\"colorB\":" + to_string(b) + "}}");
  427.           } else {
  428.             id(nspanel1).send_json_command_(0x86,"{\"id\":\"wled_test\",\"params\":{\"switch\":\"off\"}}");
  429.           }
  430.   - id: ha_plug_09_update
  431.     then:
  432.       - lambda: |-
  433.           if(id(plug_09_switch).state) {
  434.             id(nspanel1).send_json_command_(0x86,"{\"id\":\"plug_09\",\"params\":{\"switch\":\"on\"}}");
  435.           } else {
  436.             id(nspanel1).send_json_command_(0x86,"{\"id\":\"plug_09\",\"params\":{\"switch\":\"off\"}}");
  437.           }
  438.   - id: nspanel_init
  439.     then:
  440.      # Setup Widgets - must send all 8
  441.       - lambda: |-
  442.           id(nspanel1).send_json_command_(0x86,"{\"HMI_resources\":[{\"index\":1,\"ctype\":\"device\",\"id\":\"light7\",\"uiid\":52}]}");
  443.           id(nspanel1).send_json_command_(0x86,"{\"relation\":[{\"ctype\":\"device\",\"id\":\"light7\",\"name\":\"DIM09\",\"online\":1,\"params\":{\"switch\":\"off\",\"ltype\":\"white\",\"white\":{\"br\":0,\"ct\":0}}]}");
  444.       - lambda: |-
  445.           id(nspanel1).send_json_command_(0x86,"{\"HMI_resources\":[{\"index\":2,\"ctype\":\"device\",\"id\":\"wled_test\",\"uiid\":33}]}");
  446.           id(nspanel1).send_json_command_(0x86,"{\"relation\":[{\"ctype\":\"device\",\"id\":\"wled_test\",\"name\":\"WLED\",\"online\":1,\"params\":{\"switch\":\"on\"}]}");
  447.       - lambda: |-
  448.           id(nspanel1).send_json_command_(0x86,"{\"HMI_resources\":[{\"index\":3,\"ctype\":\"device\",\"id\":\"plug_09\",\"uiid\":1}]}");
  449.           id(nspanel1).send_json_command_(0x86,"{\"relation\":[{\"ctype\":\"device\",\"id\":\"plug_09\",\"name\":\"PLUG09\",\"online\":1,\"params\":{\"switch\":\"on\"}]}");
  450.       - lambda: 'id(nspanel1).send_json_command_(0x86,"{\"index\":4,\"type\":\"delete\"}");'
  451.       - lambda: 'id(nspanel1).send_json_command_(0x86,"{\"index\":5,\"type\":\"delete\"}");'
  452.       - lambda: 'id(nspanel1).send_json_command_(0x86,"{\"index\":6,\"type\":\"delete\"}");'
  453.       - lambda: 'id(nspanel1).send_json_command_(0x86,"{\"index\":7,\"type\":\"delete\"}");'
  454.       - lambda: 'id(nspanel1).send_json_command_(0x86,"{\"index\":8,\"type\":\"delete\"}");'
  455.       # Update existing Entities    
  456.       - script.execute: ha_dim_09_light_update
  457.       - script.execute: ha_wled_test_update
  458.       - script.execute: ha_plug_09_update
  459.       # Setup Thermostat
  460.       - lambda: 'id(nspanel1).send_json_command_(0x84,"{\"HMI_ATCDevice\":{\"ctype\":\"device\",\"id\":\"climate\",\"outlet\":0,\"etype\":\"hot\"}}");'
  461.       - lambda: 'id(nspanel1).send_json_command_(0x84,"{\"ATCMode\":0}");'
  462.       # Update Thermostat On/Off
  463.       - lambda: |-
  464.           if (id(climate_state).state == "heat") {
  465.            id(nspanel1).send_json_command_(0x84,"{\"ATCEnable\":1}");
  466.           } else {
  467.            id(nspanel1).send_json_command_(0x84,"{\"ATCEnable\":0}");
  468.           }
  469.       # Update Thermostat Temperature
  470.       - lambda: |-
  471.           if ( (int) id(climate_temp).state > 15 && (int) id(climate_temp).state < 32) {
  472.             id(nspanel1).send_json_command_(0x84,"{\"ATCExpect0\":" + to_string((int) id(climate_temp).state) + "}");
  473.           }
  474.   - id: nspanel_weather
  475.     then:
  476.       - logger.log: "nspanel_weather started"
  477.       - lambda: |-
  478.           WiFiClientSecure client;
  479.           HTTPClient http;
  480.           int wicon,wicon_out;
  481.           std::string buffer;
  482.           //client::setInsecure();
  483.           client.setInsecure();
  484.          
  485.           ESP_LOGD("nspanel_weather", "Init Complete");
  486.           http.begin(client,"wttr.in",443,"/ipswich?format=j2",true);
  487.           ESP_LOGD("nspanel_weather", "http.begin OK");
  488.  
  489.           int httpCode = http.GET();
  490.           ESP_LOGD("nspanel_weather", "http.GET OK");
  491.  
  492.           if (httpCode > 0) {
  493.             ESP_LOGD("nspanel_weather", "code is %i", httpCode);
  494.  
  495.             if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
  496.  
  497.               DynamicJsonBuffer doc(4000);
  498.               JsonObject& root = doc.parseObject(http.getStream());
  499.                
  500.               ESP_LOGD("nspanel_weather", "JSON Parse OK");
  501.              
  502.               if (root.containsKey("current_condition")) {
  503.              
  504.                 JsonArray& current = root["current_condition"];
  505.                 JsonObject& current_0 = current[0];
  506.                 JsonArray& weather = root["weather"];
  507.                 JsonObject& weather_0 = weather[0];
  508.  
  509.                 ESP_LOGD("nspanel_weather", "Prepare to send JSON");
  510.                
  511.                 wicon = int(current_0["weatherCode"].as<signed int>());
  512.                 ESP_LOGD("nspanel_weather", "wicon %i",wicon);
  513.                
  514.                 wicon_out = 30; // Unkown / Default
  515.                 if (wicon == 113) { wicon_out = 1; } //     # Sunny      
  516.                 if (wicon == 116) { wicon_out = 2; } //     # PartlyCloudy  
  517.                 if (wicon == 119) { wicon_out = 2; } //     # Cloudy            
  518.                 if (wicon == 122) { wicon_out = 7; } //     # VeryCloudy          
  519.                 if (wicon == 143) { wicon_out = 11; } //    # Fog                
  520.                 if (wicon == 176) { wicon_out = 40; } //    # LightShowers    
  521.                 if (wicon == 179) { wicon_out = 24; } //    # LightSleetShowers
  522.                 if (wicon == 182) { wicon_out = 24; } //    # LightSleet        
  523.                 if (wicon == 185) { wicon_out = 24; } //    # LightSleet        
  524.                 if (wicon == 200) { wicon_out = 42; } //    # ThunderyShowers  
  525.                 if (wicon == 227) { wicon_out = 20; } //    # LightSnow  
  526.                 if (wicon == 230) { wicon_out = 22; } //    # HeavySnow        
  527.                 if (wicon == 260) { wicon_out = 11; } //    # Fog                
  528.                 if (wicon == 263) { wicon_out = 40; } //    # LightShowers    
  529.                 if (wicon == 266) { wicon_out = 40; } //    # LightRain      
  530.                 if (wicon == 281) { wicon_out = 24; } //    # LightSleet        
  531.                 if (wicon == 284) { wicon_out = 24; } //    # LightSleet        
  532.                 if (wicon == 293) { wicon_out = 40; } //    # LightRain      
  533.                 if (wicon == 296) { wicon_out = 40; } //    # LightRain      
  534.                 if (wicon == 299) { wicon_out = 18; } //    # HeavyShowers      
  535.                 if (wicon == 302) { wicon_out = 18; } //    # HeavyRain        
  536.                 if (wicon == 305) { wicon_out = 18; } //    # HeavyShowers      
  537.                 if (wicon == 308) { wicon_out = 18; } //    # HeavyRain        
  538.                 if (wicon == 311) { wicon_out = 24; } //    # LightSleet        
  539.                 if (wicon == 314) { wicon_out = 24; } //    # LightSleet        
  540.                 if (wicon == 317) { wicon_out = 24; } //    # LightSleet        
  541.                 if (wicon == 320) { wicon_out = 20; } //    # LightSnow  
  542.                 if (wicon == 323) { wicon_out = 22; } //    # LightSnowShowers
  543.                 if (wicon == 326) { wicon_out = 22; } //    # LightSnowShowers
  544.                 if (wicon == 329) { wicon_out = 22; } //    # HeavySnow        
  545.                 if (wicon == 332) { wicon_out = 22; } //    # HeavySnow        
  546.                 if (wicon == 335) { wicon_out = 29; } //    # HeavySnowShowers  
  547.                 if (wicon == 338) { wicon_out = 22; } //    # HeavySnow        
  548.                 if (wicon == 350) { wicon_out = 24; } //    # LightSleet        
  549.                 if (wicon == 353) { wicon_out = 24; } //    # LightSleet        
  550.                 if (wicon == 356) { wicon_out = 18; } //    # HeavyShowers      
  551.                 if (wicon == 359) { wicon_out = 18; } //    # HeavyRain        
  552.                 if (wicon == 362) { wicon_out = 24; } //    # LightSleetShowers
  553.                 if (wicon == 365) { wicon_out = 24; } //    # LightSleetShowers
  554.                 if (wicon == 368) { wicon_out = 22; } //    # LightSnowShowers
  555.                 if (wicon == 371) { wicon_out = 29; } //    # HeavySnowShowers  
  556.                 if (wicon == 374) { wicon_out = 24; } //    # LightSleetShowers
  557.                 if (wicon == 377) { wicon_out = 24; } //    # LightSleet        
  558.                 if (wicon == 386) { wicon_out = 42; } //    # ThunderyShowers  
  559.                 if (wicon == 389) { wicon_out = 42; } //    # ThunderyHeavyRain  
  560.                 if (wicon == 392) { wicon_out = 42; } //    # ThunderySnowShowers
  561.                 if (wicon == 395) { wicon_out = 29; } //    # HeavySnowShowers  
  562.  
  563.                 id(nspanel1).send_json_command_(0x81,"{\"HMI_weather\":" + to_string(wicon_out) + ",\"HMI_outdoorTemp\":{\"current\":" + current_0["temp_C"].as<const char*>() + ",\"range\":\"" + weather_0["mintempC"].as<const char*>() + "," + weather_0["maxtempC"].as<const char*>() + "\"}}");
  564.               } else {
  565.                 ESP_LOGD("nspanel_weather", "Current Condition not found");
  566.               }
  567.             }              
  568.           }
  569.          
  570. switch:
  571.   - platform: gpio
  572.     name: Relay 1
  573.     id: ${switch_id}_relay_1
  574.     pin:
  575.       number: 22
  576.  
  577.   - platform: gpio
  578.     name: Relay 2
  579.     id: ${switch_id}_relay_2
  580.     pin:
  581.       number: 19
  582.  
  583.   - platform: gpio
  584.     name: Screen Power
  585.     id: ${switch_id}_screen_power
  586.     entity_category: config
  587.     pin:
  588.       number: 4
  589.       inverted: true
  590.     restore_mode: ALWAYS_OFF
  591.     on_turn_on:
  592.       then:
  593.         - delay: 8s
  594.         - script.execute: nspanel_init
  595.         - lambda: 'id(nspanel1).send_wifi_state_();'
  596.         - delay: 5s
  597.         - script.execute: nspanel_weather
  598.         - lambda: |-
  599.             uint8_t rssi = 0;
  600.             rssi = (wifi::global_wifi_component->wifi_rssi() * -1) / 20.0f;
  601.             std::string json_str = json::build_json([rssi](JsonObject &root) {
  602.               root["wifiState"] = "connected";
  603.               root["rssiLevel"] = rssi;
  604.             });
  605.             id(nspanel1).send_json_command_(0x85, json_str);
  606.  
  607.   - platform: template
  608.     name: NSPanel Energy Saving Mode
  609.     id: ${switch_id}_eco_mode
  610.     entity_category: config
  611.     restore_state: true
  612.     optimistic: true
  613.  
  614. rtttl:
  615.   id: ${switch_id}_buzzer
  616.   output: ${switch_id}_buzzer_out
  617.  
  618.  
  619. sensor:
  620.   - platform: adc
  621.     id: ${switch_id}_ntc_source
  622.     pin: 38
  623.     update_interval: 60s
  624.     attenuation: 11db
  625.  
  626.   - platform: resistance
  627.     id: ${switch_id}_resistance_sensor
  628.     sensor: ${switch_id}_ntc_source
  629.     configuration: DOWNSTREAM
  630.     resistor: 11.2kOhm
  631.  
  632.   - platform: ntc
  633.     id: ${switch_id}_temperature
  634.     sensor: ${switch_id}_resistance_sensor
  635.     calibration:
  636.       b_constant: 3950
  637.       reference_temperature: 25°C
  638.       reference_resistance: 10kOhm
  639.     name: "${friendly_name} Temperature"
  640.    
  641. # Home Assistant Light State Sensors to update panel
  642.   - platform: homeassistant
  643.     id: dim_09_light_bright
  644.     entity_id: light.dim_09_light
  645.     attribute: brightness
  646.     on_value:
  647.       then:
  648.         - script.execute: ha_dim_09_light_update
  649.   - platform: homeassistant
  650.     id: wled_test_bright
  651.     entity_id: light.wled_test
  652.     attribute: brightness
  653.     on_value:
  654.       then:
  655.         - script.execute: ha_wled_test_update
  656.   - platform: homeassistant
  657.     id: climate_temp
  658.     name: Climate Temp
  659.     entity_id: climate.shed
  660.     attribute: temperature
  661.     internal: false
  662.     on_value:
  663.       then:
  664.         - lambda: |-
  665.             if ((int) id(climate_temp).state > 15 && (int) id(climate_temp).state < 32) {
  666.               id(nspanel1).send_json_command_(0x84,"{\"ATCExpect0\":" + to_string((int) id(climate_temp).state) + "}");
  667.             }
  668.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement