Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DHT11 or DHT22 sensor #32

Closed
dawsmac opened this issue Apr 7, 2018 · 16 comments
Closed

DHT11 or DHT22 sensor #32

dawsmac opened this issue Apr 7, 2018 · 16 comments

Comments

@dawsmac
Copy link

dawsmac commented Apr 7, 2018

Hi
If this is a pull request sorry..

I have a few DHT11 sensors and was hoping I could add them to this setup, is it possible?

Cheers
Rich

@flyte
Copy link
Owner

flyte commented Apr 7, 2018

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.

@dawsmac
Copy link
Author

dawsmac commented Apr 8, 2018

Cool sounds good....

@dawsmac dawsmac closed this as completed Aug 14, 2018
@flyte
Copy link
Owner

flyte commented Aug 15, 2018

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

@flyte flyte reopened this Aug 15, 2018
@eXCepT74
Copy link

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

@flyte
Copy link
Owner

flyte commented Oct 26, 2018

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

@eXCepT74
Copy link

eXCepT74 commented Nov 5, 2018

@patvdleer
Copy link

Following :)

@BenjiU
Copy link
Collaborator

BenjiU commented Feb 18, 2019

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?

@flyte
Copy link
Owner

flyte commented Feb 18, 2019

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?

@BenjiU
Copy link
Collaborator

BenjiU commented Feb 19, 2019

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.

@patvdleer
Copy link

Would this work for a ds18b20 as well?

@BenjiU
Copy link
Collaborator

BenjiU commented Feb 20, 2019

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)

@gieljnssns
Copy link

@BenjiU

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

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

@julioo94
Copy link

julioo94 commented Jul 27, 2019

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

@oguven
Copy link

oguven commented Sep 3, 2019

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

@flyte
Copy link
Owner

flyte commented Jan 24, 2021

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

@flyte flyte closed this as completed Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants