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

Moderators: Voyager, BertB, rtenklooster, Stuntteam, grovkillen, TD-er

Post Reply
Message
Author
dampa
Normal user
Posts: 28
Joined: 19 Jul 2018, 01:48

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

#1 Post by dampa » 02 Apr 2019, 13:22

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!

User avatar
grovkillen
Normal user
Posts: 2886
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

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

#2 Post by grovkillen » 02 Apr 2019, 13:54

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

ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

dampa
Normal user
Posts: 28
Joined: 19 Jul 2018, 01:48

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

#3 Post by dampa » 02 Apr 2019, 14:04

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.

User avatar
grovkillen
Normal user
Posts: 2886
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

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

#4 Post by grovkillen » 02 Apr 2019, 14:54

You mean that you got more than one of these active at the same time?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

dampa
Normal user
Posts: 28
Joined: 19 Jul 2018, 01:48

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

#5 Post by dampa » 02 Apr 2019, 16:07

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.

User avatar
grovkillen
Normal user
Posts: 2886
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

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

#6 Post by grovkillen » 02 Apr 2019, 18:58

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?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

dampa
Normal user
Posts: 28
Joined: 19 Jul 2018, 01:48

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

#7 Post by dampa » 02 Apr 2019, 19:28

Hmmm, I'm going to have to ponder that idea. Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests