Jump to content

Adding Analog input to a Sonoff Basic, need to read the Sensor Value


TriLife

Recommended Posts

Posted

Greetings;

Long time no post!

I have a little project, which requires me to read water turbidity and accordingly open/close a sluice. Therea are several approaches to this,  but at first glance, the easiest is to use an existing Sonoff Basic (or SV) and have the ADC port read the value of the turbidity sensor (https://tasmota.github.io/docs/ADC/).

The Tasmota MQTT would then publish the analog reading to tele/Creek/SENSOR . So far so good.

The MQTT node server by @xKing lets me upload a .YAML file, in which I specify all the Sonoff switches I have. An individual entry looks like this:
 

- id: "Creek"
  name: "Creek Control"
  type: "switch"
  status_topic: "stat/Creek/POWER"
  cmd_topic: "cmnd/Creek/power"

The above looks just at the status of the Relay and lets me control it.

How do I add the 

tele/Creek/SENSOR

to this, so in IoP, I can read the tele/Creek/SENSOR and turn the cmnd/Creek/power ON?

I could write a rule in Tasmota for such a simple task, but eventually I need to integrate data from my Davis WeatherStation into the decision process, so I'd rather get things set up right in the first place.

Cheers!

Posted
16 hours ago, TriLife said:

Greetings;

Long time no post!

I have a little project, which requires me to read water turbidity and accordingly open/close a sluice. Therea are several approaches to this,  but at first glance, the easiest is to use an existing Sonoff Basic (or SV) and have the ADC port read the value of the turbidity sensor (https://tasmota.github.io/docs/ADC/).

The Tasmota MQTT would then publish the analog reading to tele/Creek/SENSOR . So far so good.

The MQTT node server by @xKing lets me upload a .YAML file, in which I specify all the Sonoff switches I have. An individual entry looks like this:
 

- id: "Creek"
  name: "Creek Control"
  type: "switch"
  status_topic: "stat/Creek/POWER"
  cmd_topic: "cmnd/Creek/power"

The above looks just at the status of the Relay and lets me control it.

How do I add the 

tele/Creek/SENSOR

to this, so in IoP, I can read the tele/Creek/SENSOR and turn the cmnd/Creek/power ON?

I could write a rule in Tasmota for such a simple task, but eventually I need to integrate data from my Davis WeatherStation into the decision process, so I'd rather get things set up right in the first place.

Cheers!

Follow-up on this:

The same .YAML file has another couple of items in it:

- id: "ClrTemp"
  name: "Cellar Temp"
  type: "TempHumid"
  status_topic: "tele/ClrTemp/SENSOR"
  cmd_topic: "cmnd/ClrTemp/POWER"

This answers the first question about the syntax for tele/Creek/SENSOR

the other entry is for a Sonoff 4CH unit:

# QUAD Wine Cellar (TOPIC in Sonoff MQTT CONFIG is "CLR4CH") IP x.120
- id: "ClrCinta" #{1:"Orientes", 2:"Cellar", 3:"Cinta", 4:"Floor"}
  name: "Cellar Light"
  type: "switch"
  status_topic: "stat/CLR4CH/POWER1"
  cmd_topic: "cmnd/CLR4CH/power1"
- id: "ClrFan"
  name: "Cellar Fan"
  type: "switch"
  status_topic: "stat/CLR4CH/POWER2"
  cmd_topic: "cmnd/CLR4CH/power2"
- id: "ClrOpen"
  name: "Open Cellar"
  type: "switch"
  status_topic: "stat/CLR4CH/POWER3"
  cmd_topic: "cmnd/CLR4CH/power3"
- id: "ClrClose"
  name: "Close Cellar"
  type: "switch"
  status_topic: "stat/CLR4CH/POWER4"
  cmd_topic: "cmnd/CLR4CH/power4"

So, based on this, I think I'll have to create 2 ids, one for the analog sensor, the other for the relay. Something like this:

# TOPIC in modified Sonoff SV MQTT CONFIG "Creek"!
- id: "Turbidity"
  name: "Creek Turbidity"
  type: "analog"
  status_topic: "tele/Creek/SENSOR"
- id: "Sluice"
  name: "Creek Sluice"
  type: "switch"
  status_topic: "stat/Creek/POWER"
  cmd_topic: "cmnd/Creek/power"

BTW, the ADC input takes inputs up to 1V only, so a Voltage divider is in order.

I'll update after trials.

 

  • 2 weeks later...
Posted
On 4/21/2023 at 11:50 AM, TriLife said:

Follow-up on this:

The same .YAML file has another couple of items in it:

- id: "ClrTemp"
  name: "Cellar Temp"
  type: "TempHumid"
  status_topic: "tele/ClrTemp/SENSOR"
  cmd_topic: "cmnd/ClrTemp/POWER"

This answers the first question about the syntax for tele/Creek/SENSOR

the other entry is for a Sonoff 4CH unit:

# QUAD Wine Cellar (TOPIC in Sonoff MQTT CONFIG is "CLR4CH") IP x.120
- id: "ClrCinta" #{1:"Orientes", 2:"Cellar", 3:"Cinta", 4:"Floor"}
  name: "Cellar Light"
  type: "switch"
  status_topic: "stat/CLR4CH/POWER1"
  cmd_topic: "cmnd/CLR4CH/power1"
- id: "ClrFan"
  name: "Cellar Fan"
  type: "switch"
  status_topic: "stat/CLR4CH/POWER2"
  cmd_topic: "cmnd/CLR4CH/power2"
- id: "ClrOpen"
  name: "Open Cellar"
  type: "switch"
  status_topic: "stat/CLR4CH/POWER3"
  cmd_topic: "cmnd/CLR4CH/power3"
- id: "ClrClose"
  name: "Close Cellar"
  type: "switch"
  status_topic: "stat/CLR4CH/POWER4"
  cmd_topic: "cmnd/CLR4CH/power4"

So, based on this, I think I'll have to create 2 ids, one for the analog sensor, the other for the relay. Something like this:

# TOPIC in modified Sonoff SV MQTT CONFIG "Creek"!
- id: "Turbidity"
  name: "Creek Turbidity"
  type: "analog"
  status_topic: "tele/Creek/SENSOR"
- id: "Sluice"
  name: "Creek Sluice"
  type: "switch"
  status_topic: "stat/Creek/POWER"
  cmd_topic: "cmnd/Creek/power"

BTW, the ADC input takes inputs up to 1V only, so a Voltage divider is in order.

I'll update after trials.

 

This worked, kind of.

First, the ADC on the Sonoff (3 different units) was given erratic readings. So I ended up ordering a WeMo Mini D1. That worked well.

And with the Yaml as shown, I can get readings of ADC and tue relay in the IoX.

I cannot, however seem to access the ADC to write a program in IoX. Started a separate thread on this. So far no news on how to fix it.

 

Cheers. 

Guest
This topic is now closed to further replies.

×
×
  • Create New...