GithubHelp home page GithubHelp logo

DHT11 or DHT22 sensor about mqtt-io HOT 16 CLOSED

flyte avatar flyte commented on July 17, 2024 3
DHT11 or DHT22 sensor

from mqtt-io.

Comments (16)

flyte avatar flyte commented on July 17, 2024

Hmm, that would be handy, wouldn't it? It's not possible right now, but I'll have a think about it and see if I can include it next time I work on the project.

from mqtt-io.

dawsmac avatar dawsmac commented on July 17, 2024

Cool sounds good....

from mqtt-io.

flyte avatar flyte commented on July 17, 2024

Reopening to keep the feature request around for if I ever get some time off to work on it.

from mqtt-io.

eXCepT74 avatar eXCepT74 commented on July 17, 2024

Is that possible to add support for MCP23017 - it has 16 I/O ports , I2C and each port can be loaded with 20mA , it has as well switchable active pullup resistors. I probably will use ur project to control my smart house based on PCF, but MCP is good idea as well. For now i see that will need at least two expanders on pcf... If i use two expanders with same addresses whether those two will be work same - i mean - if ill connect leds to both - the states of leds will be same or on i2c will be conflict due to same addresses ? i need one pcf to connect to control lamps ( leds )for my house. Anyway great project! Keep going like that!!! regards

from mqtt-io.

flyte avatar flyte commented on July 17, 2024

Hey @eXCepT74

The MCP23017 is certainly suitable for use with this project, but could you make a separate Issue please? You can just copy and paste your comment into a new one.

Cheers

from mqtt-io.

eXCepT74 avatar eXCepT74 commented on July 17, 2024

from mqtt-io.

patvdleer avatar patvdleer commented on July 17, 2024

Following :)

from mqtt-io.

BenjiU avatar BenjiU commented on July 17, 2024

Currently I'm working on the interrupt issue (#5), but how may a yaml config for dht11/dht22 look? You have two values on one sensor, that should appear in two different topics. My suggestion (I steel the config idea as I've implemented it for lm75 i2c temperatur sensor in pullrequest #52)

sensor_modules:             //list for all sensor_modules, like for gpio_modules
  - name: dht11_sensor_temperature
    module: dht11
    gpio: 16                        //pin dht11 sensor is connected to
    value: temperatur          
  - name: dht11_sensor_humidity
    module: dht11
    gpio: 16                        //pin dht11 sensor is connected to
    value: humidity

So we config the dht11/22 sensor twice on the same pin. First time with temperature value and second time with humidity value. These values will be passed to module instance and stored intern, to select which value should be returned.

In the sensor_inputs we create two entries, too, first using the dht11_sensor_temperature and second using dht11_sensor_humidity. This gives us the possibility to configure the mqtt topic and for example different update times:

sensor_inputs:
  - name: my_temperature              // mqtt topic
    module: dht11_sensor_temperature
    interval: 120                                // 2*60sec, each 2 min
    digits: 2                                       // digits to round the value to
  - name: my_humidity
    module: dht11_sensor_humidity
    interval: 240                               // e.g. every 4 minutes
    digits: 1

This should create the following mqtt topics with values:

mydevice/sensor/my_temperature 19.50
mydevice/sensor/my_temperature 19.50
mydevice/sensor/my_humidity 41.0
mydevice/sensor/my_temperature 19.50
mydevice/sensor/my_temperature 19.50
mydevice/sensor/my_humidity 41.0

Any suggestions or does someone see a problem?

from mqtt-io.

flyte avatar flyte commented on July 17, 2024

It would be nice to keep the module configs 1:1 with the physical modules, so in sensor_modules it should be listed once. The module name doesn't have a bearing on the topic, so the temperature/humidity configuration could be on the sensor_inputs instead. Something like:

sensor_modules:
  - name: dht11_sensor
    module: dht11
    i2c_bus_num: 1
    chip_addr: 0x20

sensor_inputs:
  - name: livingroom_temp
    module: dht11_sensor
    interval: 120
    digits: 2
    sensor: temperature
  - name: livingroom_humidity
    module: dht11_sensor
    interval: 240
    digits: 1
    sensor: humidity

What do you reckon?

from mqtt-io.

BenjiU avatar BenjiU commented on July 17, 2024

That's of course the better solution. I already implemented this "interface" for LM75 I2C sensor on the other branch: when getting the value from the sensor in the sensor_timer_thread, the sensor is passed to the read function. We just need to pass the sens_conf to the get_value() function, instead of the sensor value:

                sensor = SENSOR_MODULES[sens_conf["module"]]
                try:
                    value = round(sensor.get_value(sensor),
                                  sens_conf["digits"])

the get_value function can now evaluate the sensor attribute and return the value.

I have two other points:

  1. Does someone know a good, free, usable DHT11/22 library?
  2. I read, that the DHT11/22 sensor shouldn't be read more often then every 1 or 2 seconds. This should be kept in mind for implementation: if we read the temperature with the first get_value() call, and directly after this the humidity with the second get_value(), the DHT sensor class must recognize this and return the previous read value, and is not allowed to read the DHT11/22 again within this short time.

from mqtt-io.

patvdleer avatar patvdleer commented on July 17, 2024

Would this work for a ds18b20 as well?

from mqtt-io.

BenjiU avatar BenjiU commented on July 17, 2024

Would this work for a ds18b20 as well?

No, as far as I know, one wire from dht11 and one wire from ds18b20 are incompatible. So you should create a new issue for ds18b20, if you want it to be supported. Maybe you could try a library, that should be supported and mention it there. (e.g. https://github.com/timofurrer/w1thermsensor)

from mqtt-io.

gieljnssns avatar gieljnssns commented on July 17, 2024

@BenjiU

Does someone know a good, free, usable DHT11/22 library?

Maybe this one?
https://github.com/adafruit/Adafruit_Python_DHT

from mqtt-io.

julioo94 avatar julioo94 commented on July 17, 2024

Hello,

I can not walk to module it shows me this error message

Config did not validate:
sensor_inputs:
- 0:
 - type:
   - unknown field
 1:
 - type:
   - unknown field

here is my config.yml file

mqtt:
  host: 192.168.0.85
  port: 1883
  user: ""
  password: ""
  topic_prefix: home
 

sensor_modules:
  - name: dht22
    module: dht22
    type: DHT22
    pin: 17

sensor_inputs:
  - name: dht22_temperature
    module: dht22
    interval: 10
    digits: 4
    type: temperature

  - name: dht22_humidity
    module: dht22
    interval: 10
    digits: 4
    type: humidity

I work on rasbian Buster I have installed the library Adafruit-DHT,

I also try on rasbian jessie but nothing always the same mistake ...

when I do ./AdafruitDHT.py 22 17 it works well and returns me as a result:

Temp=23.2* Humidity=74.8%

an idea of ​​where is my problem?

PROBLEM SOLVED i had to redo the installation manually the dht22.py module was wrong

from mqtt-io.

oguven avatar oguven commented on July 17, 2024

Hello,

I'm also having the same problem with DHT11.

Installed pi-mqtt-sensor and Adafruit_Python_DHT with pip (sudo privileges)

My config file works without sensor lines. When I add DHT sensor lines;

Config did not validate:
sensor_inputs:
- 0:
  - type:
    - unknown 

here my config.yml

mqtt:
  host: (webaddress)
  port: (port)
  tls:
    enabled: yes
    cert_reqs: CERT_NONE
    insecure: yes
  user: "(user)"
  password: "(pass)"
  topic_prefix: station
  status_topic: status
  status_payload_running: running
  status_payload_stopped: stopped
  status_payload_dead: dead

gpio_modules:
  - name: raspberrypi
    module: raspberrypi

sensor_modules:
  - name: dht22
    module: dht22
    type: dht11
    pin: 5

sensor_inputs:
  - name: dht22_temperature
    module: dht22
    interval: 10
    digits: 4
    type: temperature

from mqtt-io.

flyte avatar flyte commented on July 17, 2024

I believe this is fixed now. Please feel free to comment if it's not.

from mqtt-io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.