Page 1 of 1

Any way to check if a device exists - in a rule?

Posted: 02 Apr 2019, 13:22
by dampa
trying to write a generic set of rules to report temperature, humidity and pressure. The idea is to install this on several devices but I won't know if a dht22, ds18b20, bmp280 or bme280 is installed and it is possible more than one is installed. Right now I have:

if [dht22#temperature] > 0
TaskValueSet,11,1,[dht22#temperature]
TaskValueSet,11,2,[dht22#humidity]
endif

if [ds18b20#temperature] > 0
TaskValueSet,11,1,[ds18b20#temperature]
endif

if [bmp280#temperature] > 0
TaskValueSet,11,1,[bmp280#temperature]
TaskValueSet,11,3,[bmp280#pressure]
endif

if [bme280#temperature] > 0
TaskValueSet,11,1,[bme280#temperature]
TaskValueSet,11,2,[bme280#humidity]
TaskValueSet,11,3,[bme280#pressure]
endif

which should cause the more accurate device to override a value.

HOWEVER, I just realized if it gets really really cold (0 or below) the measurement won't take place.

Anyone got any thoughts on a better way to do this?

Thanks!

Re: Any way to check if a device exists - in a rule?

Posted: 02 Apr 2019, 13:54
by grovkillen
Since the events of the devices will never trigger if it's not set up you could do it like this instead:

Code: Select all

On dht22#temperature Do
TaskValueSet,11,1,[dht22#temperature]
TaskValueSet,11,2,[dht22#humidity]
EndOn

On ds18b20#temperature Do
TaskValueSet,11,1,[ds18b20#temperature]
EndOn

On bmp280#temperature Do
TaskValueSet,11,1,[bmp280#temperature]
TaskValueSet,11,3,[bmp280#pressure]
EndOn

On bme280#temperature Do
TaskValueSet,11,1,[bme280#temperature]
TaskValueSet,11,2,[bme280#humidity]
TaskValueSet,11,3,[bme280#pressure]
EndOn


Re: Any way to check if a device exists - in a rule?

Posted: 02 Apr 2019, 14:04
by dampa
That's great idea except ift the bme280 triggers then the dht22 triggers, the readings from the bme280 will be overwritten and I'll get the dht22 readings. Getting the bme280 readings are better than the dht22 readings.

Re: Any way to check if a device exists - in a rule?

Posted: 02 Apr 2019, 14:54
by grovkillen
You mean that you got more than one of these active at the same time?

Re: Any way to check if a device exists - in a rule?

Posted: 02 Apr 2019, 16:07
by dampa
Yes, the bmp280 reports temperature and pressure but not humidity, so I have a dht22 connected also. With the if statements it would grab the temp and humidity from the dht22 then overwrite the temperature and add the pressure from the bmp280.

Myself and another guy are building DIY weather reporting system with Node-RED and devices using ESPeasy, to show kids how IOT works. He is in England, I'm in the US so they can grab the readings from all the devices and it can now be displayed on a worldmap. The data is shared using MQTT via beebotte.com and is working pretty well.

There has been some mission creep ;) as it started as just reporting the data in a table, but it has expanded a little :lol:

I have to say that it has been a challenge to code with rules with the 2048 character limit. long variable names become reduced to single characters at times. Reminds me of the first language I learned - Focal-7 you could only have a maximum of 40 lines with one command on each line.

Re: Any way to check if a device exists - in a rule?

Posted: 02 Apr 2019, 18:58
by grovkillen
You can have up to 4 pages of code which will work as "one page".

The events could equal to 1, 10, 100, 1000 depending on which unit or units are available. Given that your unit have a DS18b20 and one bme280 the sum reported would be 1010. And you could activate reports of values based on these codes?

Re: Any way to check if a device exists - in a rule?

Posted: 02 Apr 2019, 19:28
by dampa
Hmmm, I'm going to have to ponder that idea. Thanks!