Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2023:homeassistantsmartswitch [2023/12/12 15:18]
norbert.zsugya
iothings:proiecte:2023:homeassistantsmartswitch [2024/01/15 11:17] (current)
norbert.zsugya
Line 4: Line 4:
  
 Mater: ACES II Mater: ACES II
 +
 +Video, Presentation and Source code: https://​1drv.ms/​f/​s!AiFSSSAJY4tDjVj-gACJLlt7F4Vg?​e=sLH02d
  
 **Objective** **Objective**
Line 12: Line 14:
  
 Components: Components:
-  * Digital Microphone +  * [[https://​www.aliexpress.com/​item/​32994999776.html|Digital Microphone]] 
-  * Esp8266 Board (NodeMCU 1.0 ESP-12E Module) +  * [[https://​www.optimusdigital.ro/​ro/​placi-esp8266/​3312-plusivo-micro-placa-de-dezvoltare-wifi-cu-esp8266-i-ch340g.html|Esp8266 Board (NodeMCU 1.0 ESP-12E Module)]] 
-  * LoRa RFM95 module +  * [[https://​ardushop.ro/​ro/​home/​1875-modul-lora-sx1278-433mhz-long-range.html?​gclid=Cj0KCQiAsburBhCIARIsAExmsu7zoA0YwKRfvD6Yn8QALD1d4qMPaiPbKarAgnLjYPcne70FPnypXS4aAomHEALw_wcB|LoRa RFM95 module]] 
-  * Tuya smart switch+  * [[https://​www.emag.ro/​intrerupator-inteligent-cu-touch-tuya-life-smart-wi-fi-cu-sau-fara-nul-1-canal-10a-sticla-securizata-compatibil-amazon-alexa-google-assistant-alb-smw18/​pd/​D0WNNMYBM/?​utm_campaign=share_product&​utm_source=mobile_dynamic_share&​utm_medium=android|Tuya smart switch]] 
 + 
 +The schematic diagram of the connections between ESP8266, Microphone and LoRa RFM95 is the following:​ 
 + 
 +{{ :​iothings:​proiecte:​2023:​system_diagram.png?​300 ||System Schematic Diagram}}
  
 **Software description & implementation** **Software description & implementation**
Line 27: Line 33:
   * ESP8266 sensor – it detects the claps using the microphone and sends status to the bridge when a clap is detected.   * ESP8266 sensor – it detects the claps using the microphone and sends status to the bridge when a clap is detected.
  
-{{ wiki:dokuwiki-128.png |System architecture}}+{{ :iothings:​proiecte:​2023:​architecture.png?300 ||System architecture}}
  
-Having a sensor and a bridge enables the fact that the sensor can be placed at a long distance from Wi-Fi router, feature enabled by LoRa protocol.+Having a sensor and a bridge enables the fact that the sensor can be placed at a long distance from Wi-Fi router, feature enabled by LoRa protocol. This architecture is IoT Level 5, meaning that we have a cloud application,​ a coordinator node and many end nodes.
  
   * Home Assistant dashboard   * Home Assistant dashboard
Line 35: Line 41:
 The dashboard for controlling the lights can be used from both web browser or mobile application and it is fully customizable. The dashboard for controlling the lights can be used from both web browser or mobile application and it is fully customizable.
  
-{{ wiki:dokuwiki-128.png }}+{{ :iothings:​proiecte:​2023:​home_assstant_dashboard.png?500 }} 
 + 
 +{{ :​iothings:​proiecte:​2023:​home_assistant_phone.jpeg?​200 ​}}
  
  
Line 42: Line 50:
 For controlling the smart switch using Tuya plugin, I set an automation scene which sets the state of the switch when a new value on MQTT clap detection topic is reached. For controlling the smart switch using Tuya plugin, I set an automation scene which sets the state of the switch when a new value on MQTT clap detection topic is reached.
  
-{{ wiki:dokuwiki-128.png }}+{{ :iothings:​proiecte:​2023:​home_assistant_scene.png?500 }}
  
  
Line 49: Line 57:
 There are necessary the following MQTT settings for Home Assistant server to be able to communicate with the subscriber. There are necessary the following MQTT settings for Home Assistant server to be able to communicate with the subscriber.
  
-{{ wiki:​dokuwiki-128.png }} 
  
 +  #add mqtt devices
 +  mqtt:
 +    sensor:
 +      - state_topic:​ "​home/​livingroom/​temp"​
 +    switch:
 +      - unique_id: livingroom_led_switch
 +        name: "​Livingroom Led Switch"​
 +        state_topic:​ "​home/​livingroom/​led_switch"​
 +        command_topic:​ "​home/​livingroom/​led_switch/​cmd"​
 +        #​availability:​
 +        #  - topic: "​home/​bedroom/​switch1/​available"​
 +        payload_on: "​255"​
 +        payload_off:​ "​0"​
 +        state_on: "​255"​
 +        state_off: "​0"​
 +        optimistic: false
 +        qos: 2
 +        retain: true
 +
 +  void callback_LoRa(int packetSize) {
 +    // received a packet
 +    TRACE_LOG("​Received packet '"​);​
 +    // read packet
 +    String message = LoRa.readString();​
 +    TRACE_LOG(message);  ​
 +    // print RSSI of packet
 +    TRACE_LOG("'​ with RSSI ");
 +    TRACE_LOGln(LoRa.packetRssi());​
 +    if(message == LIVING_LED_SWITCH_CMD.path){
 +      led_state = 255 - led_state;
 +      digitalWrite(LED_PIN,​ 255 - led_state);  ​
 +      client.publish(LIVING_LED_SWITCH_STATE.path.c_str(),​ String(led_state).c_str());  ​
 +    }  ​
 +  }
  
 Clap detection function features: Clap detection function features:
Line 56: Line 97:
   * Detects if so many claps within a short period of time and disables for some time the clap detection feature. This feature allows noise detection having a safety purpose, so the switch and light do not turn on and off so many times in a short interval if there is noise inside the house.   * Detects if so many claps within a short period of time and disables for some time the clap detection feature. This feature allows noise detection having a safety purpose, so the switch and light do not turn on and off so many times in a short interval if there is noise inside the house.
   * There are 3 versions of clap detection function which are implemented. The last version does an average reading on the digital input pin and performs average on the reading values. This feature is also added for robustness, so small microphone noise inputs to be ignored.   * There are 3 versions of clap detection function which are implemented. The last version does an average reading on the digital input pin and performs average on the reading values. This feature is also added for robustness, so small microphone noise inputs to be ignored.
 +
 +  //reset clap_counts
 +  if(clap_counts >= NOISE_CLAPS_NO){
 +    if ((millis() - last_clap_millis) <= NOISE_DETECTION_INTERVAL){
 +      TRACE_LOGln("​Detected " + String(clap_counts) + " claps in " + String(NOISE_DETECTION_INTERVAL) + "s. Disabling Clap feature for " + String(CLAP_FEATURE_DISABLE_TIME) + "​s"​);​
 +      clap_enable = DISABLED;
 +    }
 +    clap_counts = 0;
 +    last_clap_millis = millis();
 +    TRACE_LOGln("​Reset clap abundance phase"​);​
 +  }
 +  // enable again clap feature
 +  if ((millis() - last_clap_millis) >= CLAP_FEATURE_DISABLE_TIME && clap_enable == DISABLED){
 +    clap_enable = ENABLED;
 +    TRACE_LOGln("​Clap feature enabled"​);​
 +  }
  
  
Line 75: Line 132:
   - ESP32 LoRa communication https://​randomnerdtutorials.com/​esp32-lora-rfm95-transceiver-arduino-ide/​   - ESP32 LoRa communication https://​randomnerdtutorials.com/​esp32-lora-rfm95-transceiver-arduino-ide/​
   - Tuya plugin in Home Assistant https://​www.youtube.com/​watch?​v=f8-7Hvrmh3Y&​t=753s   - Tuya plugin in Home Assistant https://​www.youtube.com/​watch?​v=f8-7Hvrmh3Y&​t=753s
-  - https://​www.aliexpress.com/​item/​32994999776.html 
-  - https://​www.optimusdigital.ro/​ro/​placi-esp8266/​3312-plusivo-micro-placa-de-dezvoltare-wifi-cu-esp8266-i-ch340g.html 
-  - https://​ardushop.ro/​ro/​home/​1875-modul-lora-sx1278-433mhz-long-range.html?​gclid=Cj0KCQiAsburBhCIARIsAExmsu7zoA0YwKRfvD6Yn8QALD1d4qMPaiPbKarAgnLjYPcne70FPnypXS4aAomHEALw_wcB 
-  - https://​www.emag.ro/​intrerupator-inteligent-cu-touch-tuya-life-smart-wi-fi-cu-sau-fara-nul-1-canal-10a-sticla-securizata-compatibil-amazon-alexa-google-assistant-alb-smw18/​pd/​D0WNNMYBM/?​utm_campaign=share_product&​utm_source=mobile_dynamic_share&​utm_medium=android 
   - https://​how2electronics.com/​lora-sx1278-esp8266-transmitter-receiver/​   - https://​how2electronics.com/​lora-sx1278-esp8266-transmitter-receiver/​
  
  
iothings/proiecte/2023/homeassistantsmartswitch.1702387128.txt.gz · Last modified: 2023/12/12 15:18 by norbert.zsugya
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0