This shows you the differences between two versions of the page.
iothings:proiecte:2023:homeassistantsmartswitch [2023/12/13 11:22] 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 16: | Line 18: | ||
* [[https://ardushop.ro/ro/home/1875-modul-lora-sx1278-433mhz-long-range.html?gclid=Cj0KCQiAsburBhCIARIsAExmsu7zoA0YwKRfvD6Yn8QALD1d4qMPaiPbKarAgnLjYPcne70FPnypXS4aAomHEALw_wcB|LoRa RFM95 module]] | * [[https://ardushop.ro/ro/home/1875-modul-lora-sx1278-433mhz-long-range.html?gclid=Cj0KCQiAsburBhCIARIsAExmsu7zoA0YwKRfvD6Yn8QALD1d4qMPaiPbKarAgnLjYPcne70FPnypXS4aAomHEALw_wcB|LoRa RFM95 module]] | ||
* [[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]] | * [[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 29: | Line 35: | ||
{{ :iothings:proiecte:2023:architecture.png?300 ||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 71: | Line 77: | ||
retain: true | 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 76: | 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"); | ||
+ | } | ||