Skip to content

custom device MQTT 'Ozone_PDMtimer' case study

Marco Sillano edited this page Apr 15, 2022 · 21 revisions

custom device MQTT 'Ozone_PDMtimer'

timer features

This is a DIY specialized timer for Ozone generators for domestic sanitation, build starting from Sonoff S20 (power plug) or a Sonoff basic and the esp_MQTT firmware. The Sonoff switches are perfects, as price and form factors, for this application, and they are easy to use. The features of the timer are:

  • PDM power control: 2%-100% to better control the Ozone production (see 'Strategies in the use of ozone' in Ozone-coronavirus-sonoff).
  • Mode LOOP: for continuous cyclic use and low concentrations. Time ON 1min..6h, time OFF 1min..6h.
  • Mode AUTO: only one cycle for chock sanitation, with a manual or remote or timed start. The manual start is delayed by 1 minute to allow the user to exit.
  • Wifi: AP for the Wifi setup and for use without a router, STA for use with a router, OTA for the software update.
  • The features of this timer are not easy implementable with a standard tuya switch, a custom solution is better.

This Ozone_PDMtimer has two interfaces (not using tuyaDEAMON):

  1. PC node-red interface, more complete: to guide the user, the UI enables or disables the controls according to the current state.
  2. Android smartphone, simpler and more standard, created using IoT MQTT Panel, see files.
The original 'Ozone_PDMtimer' can be used:
- **Standalone**: the timer is used alone, controlling it with its button. Portable, but the timer must be configured in advance.
- **SoloAP**: The timer is configured as AP, the client (e.g. a smartphone) must have the WiFi connected directly to the timer AP.
- **LanRouter** The timer is configured as STA and connects to the router's WiFi. The timer uses an NTP server to get the exact time.

The details of the MQTT 'Ozone_PDMtimer' project can be found here: https://github.com/msillano/Ozone-coronavirus-sonoff/blob/master/PROJECTS-DIY/timerPDM/timerPDM_sonoff_en.pdf.

tuyaDAEMON integration

Why integrate this MQTT Ozone_PDMtimer in tuyaDAEMON?

  • With TRIGGERs, we can control the timer and get notifications from any distance.
  • The DB data logging can enable statistical and commercial extensions.
  • Automations can be build to do sanification in an automatic way (e.g. when the home is empty).
  • It is a simple but good example of MQTT devices integration in tuyaDAEMON, easily reusable.

For the integration, I make a subflow that directly replaces the tuya-smart-device node, so this MQTT device is, for tuyaDAMON, a 'real' device. I used the 'dynamic retry' node because the timer and the ozone generator are often unplugged from the power outlet. "REFRESH" subflow is not required.

I defined the DPs, using tuyaDAEMON.toolkit and the same names used in MQTT, with few exceptions, so the implementation is a simple protocol change. Because the Ozone_PDMtimer sends an _info message every second, I implemented refreshCycle inside the subflow, mostly to reduce the rate.

files:

reuse

The original timer project was designed without thinking about the Tuya IoT model, but to simplify the UI and with the constraint of a limited amount of device memory, so the 'Ozone_PDMtimer' behavior is not standard: SET responds with many DPs but not all, SCHEMA is not implemented, etc.

Despite this, the conversion from/to MQTT is still simple and can be also simpler in new projects, if they more strictly follow Tuya's conventions. So this is a viable way to integrate many custom or third-party MQTT devices into the tuyaDAEMON system.


version 2.2.0

Update version, REFRESH implementation rewritten.

Clone this wiki locally