bme680 bmp280 AM2302 dht22 433 rflink lan raspberry

Moderator: leecollings

Post Reply
jody2
Posts: 2
Joined: Thursday 02 April 2020 10:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

bme680 bmp280 AM2302 dht22 433 rflink lan raspberry

Post by jody2 »

hi all,

i have a few pi 3b+ with raspbian buster and latest domoticz installed at my house. I have a bunch of sensors connected among others the bme680 bmp280, AM2302, dht22 and also several 433mhz transmitter and receiver (e.g. mx-rm-5v, aprxb12, APF03, all of which atm I use to switch on/off electricity to plugged in appliances). All devices are connected via gpio to my raspberries.
System info from domoticz/pi:
Pi 3B+
Linux pi 4.19.97-v7+ #1294 SMP Thu Jan 30 13:15:58 GMT 2020 armv7l GNU/Linux
Raspbian GNU/Linux 10 (buster)

Domoticz-info:
Version: 2020.1
Build Hash: 63fa969e4
Compile Date: 2020-03-22 15:16:16
dzVents Version: 3.0.1
Python Version: 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0]
I of course did a lot of searching on the internet and I also saw that there are similar sensors or sensors with same serial/product number but looked a little different. Here links to the ones that I use to be avoid confusion.
The sensor readings I was getting into domoticz via python scripts and it works e.g. for the AM2302 I created a first under the hardware tab a virtual sensor. Then I checked in the "devices" tab what the "IDX" value is for the newly created virtual sensor. The AM2302 on BCM pin 4 on my PI so my python script looks like this:

Code: Select all

#!/usr/bin/python
import sys
import Adafruit_DHT
import urllib

# parameters
DHT_type    = 2302
OneWire_pin = 4
sensor_idx  = 1382
url_json    = "http://192.168.1.33:8080/json.htm?type=command&param=udevice&idx="

# read dht11 temperature and humidity
humidity, temperature = Adafruit_DHT.read_retry(DHT_type, OneWire_pin)

# use Domoticz JSON url to update
cmd = url_json  + str(sensor_idx) + "&nvalue=0&svalue=" + str(temperature) + ";" + str(humidity) + ";0"
hf = urllib.urlopen(cmd)
this works fine. I then run a cron job ever 5 mins to get the values into domoticz.
On another PI I have attached two sensors via SPI the bmp280 and via I2C the BME680. The bmp280 first, this sensor gives temperature, pressure and altitude. There seems to be no virtual sensor that had the combination of these three so I thought let's go for separate virtual sensors in domoticz, one sensor temp&pressure (after creation IDX 1408) and one that will show my altitude (after creation IDX 1410). The values for temperature are displayed under the tab "Temperature" but with many decimals behind it, is there no way to only show e.g. 2 decimals there? and the pressure is displayed under the "Weather" tab but also with many decimals (see screens below python code), would also be nice to get his rounded.
Code for Temp+Pressure:

Code: Select all

#!/usr/bin/python3
import sys
import urllib.request
import time
import board
import busio
import digitalio
import adafruit_bmp280
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.D5)
sensor = adafruit_bmp280.Adafruit_BMP280_SPI(spi, cs)

sensor_idx  = 1408
url_json    = "http://192.168.1.33:8080/json.htm?type=command&param=udevice&idx="

print('Temperature: {} degrees C'.format(sensor.temperature))
print('Pressure: {}hPa'.format(sensor.pressure))
sensor.sea_level_pressure = 1013.25
print('Altitude: {} meters'.format(sensor.altitude))

cmd = url_json  + str(sensor_idx) + "&nvalue=0&svalue=" + str(sensor.temperature) + ";" + str(sensor.pressure) + ";0"
hf = urllib.request.urlopen(cmd)
Output on cli when running script:
Image
What is seen on the domoticz page:
Image
Image

Then we come to the bme680. This sensor gives temperature, humidity, pressure, and indoor air quality. There is no virtual sensor in domoticz that combines it all, so again I thought let's create multiple virtual sensors. Let's start with one virtual sensor for "temp, hum, pressure", create with IDX 1425. The python script works fine on the pi cli:

Code: Select all

#!/usr/bin/env python3
import bme680
import time
import sys
import urllib.request

sensor = bme680.BME680()

sensor_idx  = 1425
url_json    = "http://192.168.1.33:8080/json.htm?type=command&param=udevice&idx="

sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_filter(bme680.FILTER_SIZE_3)

print('Temperature: {0:0.1f}'.format(sensor.data.temperature))
print('Humidity: {0:0.1f} %RH'.format(sensor.data.humidity))
print('Pressure: {0:0.1f} hPa'.format(sensor.data.pressure))

cmd = url_json  + str(sensor_idx) + "&nvalue=0&svalue=" + str(sensor.data.temperature) + ";" + str(sensor.data.humidity) + ";" + "0" + ";" + str(sensor.data.pressure) + ";0"
hf = urllib.request.urlopen(cmd)
and returns the following on the cli
Temperature: 12.8
Humidity: 55.1 %RH
Pressure: 1022.1 hPa
How to get the indoor air-quality values into domoticz from this sensor?

As I mentioned I also have a 433 receiver and transmitter hooked to my pi via the gpio pins up for remote plugs. I'm using rflink lan gateway https://github.com/seahu/rflink Under the tab "switches" there is the "learn light switch" when I try it with the remote for the plugs it doesn't properly get the codes I think. It saves some codes, then displays a switch (mostly as x10 although these are not x10) and the domoticz interface buttons don't work to control the plugs. I tried many times, for some reason when I first used the off button on the remote for 2 devices it did recognize them as ELRO plugs (which they are not) and the codes worked for those from the domoticz interface and I could control them. In the end as I went to run shell scripts to run my switches that was using before domoticz (using https://github.com/ninjablocks/433Utils) but I would like to get the "learn light/switch" function to work properly, what am I doing wrong? because the RFsniffer of ninjablocks works just fine.
Another way to add learning switches with diy 433 is via this:
https://www.domoticz.com/wiki/Plugins/RFSwitches
Which works fine but when using this and switching a button on or off there is a noticeable delay. It takes like 3-4 seconds after the click that the remote device responds, not sure what domoticz is doing internal to cause this.
A way to get responses much quicker is to use a webserver that turns devices off or on from a php script that runs a command in shell. So I already have apache installed on my pi. As I mentioned earlier I was/am using wiringPI and ninjablocks 433 utils from the shell to control devices, e.g. my black lightbeam is controlled from the command line with, e.g. to turn on:
/path/to/script/ 1
So now you just need put this in a php file on your webserver, e.g. bathroom_on.php:
<?php
$output = shell_exec('/home/pi/Downloads/433Utils/RPi_utils/Bathroom 1');
echo "<pre>$output</pre>";
?>
This I add to a virtual switch that I created and added the link to to the switches as http to run on click, same for the off button. This responds within a 1 second in comparision to the domoticz 433 solution.
thank you in advance for any tips and pointers!
User avatar
profeta64
Posts: 8
Joined: Saturday 11 February 2017 17:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Bayern
Contact:

Re: bme680 bmp280 AM2302 dht22 433 rflink lan raspberry

Post by profeta64 »

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests