Page 1 of 1

Switch something with sensor values

Posted: Sunday 09 May 2021 0:22
by CoolRemote
Hello, After adding succesfully sensors like LDR and BMP180 I would like to do something with the values coming from these sensors. Where possible I would prefer to keep this "basic and easy to understand", so if possible no MQTT or Blockly or similar protocols for now.

I thought about adding relay card that will switch when the sensors reach a certain level, and also I have been looking if the "notifications" option in Domoticz can be helpful for this, but did not find a solution yet. I would like for example that a relay will turn on when the LDR value is reaching let's 90 Lux, or when the BPM180 is reaching 20 degree celcius.

Looking forward to suggestions

Re: Switch something with sensor values

Posted: Sunday 09 May 2021 11:01
by psubiaco
Hi,
I suggest to write a LUA or dzEvenet script for this.
Making a script from Domoticz user interface is quite simple: Domoticz already prepare you a script draft with several information.
Then, when scripting becomes familiar for you, you'll ready to do great jobs with Domoticz + scripting.
For example, in my house I have a LUA script that manages about 60 magnetic contact sensors, some PIRs, and sirens, to get a complete burglar alarm system.
Another LUA script that manages heating/cooling optimizing the heat pump power consumption and improving the own-consumption (I have a photovoltaic system on the roof).
You can find those scripts at https://github.com/CreasolTech/domoticz_lua_scripts
In your case, if you'd like to try to make a lua script, just create a sample LUA script in domoticz: Setup -> More options -> Event
then click on + icon and select Lua -> Time (script executed every 1 minute: or Lua -> Device if you want a script executed when LUX device changes)

The script should be something like this:

Code: Select all

commandArray = {}

if (otherdevices["LUX"]>=90 and otherdevices["RELAY"]=='Off') then
    commandArray["RELAY"]="On"
end    
return commandArray
When the sensor named "LUX" has value >=90 and the device "RELAY" is off, send command to Domoticz to activate device named "RELAY"
Very simple!
Good luck

Re: Switch something with sensor values

Posted: Sunday 09 May 2021 21:21
by CoolRemote
Thank you very much psubiaco! Happy to re-read your suggestions and give it a try. :D

I've been struggling to get the sensors working, that means to have the values displayed in Domoticz, even if I followed examples. Some online examples are not complete because some go in their examples from the viewpoint that the other one reading/watching them knows already what to do, but that is not always the case. In that sort of cases there is in the user manual often a service or help desk you can call if you still don't know what to do. Asuming that the service or help desk knows the proper answer it will be ok, otherwise...lol. But YouTube or other examples online don't come with a service or help desk you can call, which means after all you have to find out for yourself. :lol: After all the positive side of this is that once you learn something you won't forget it that easily! ;)

Since this spring season is not really spring, but more like 4 seasons in 1 day it is the perfect moment to stay inside and give this a try.

I also found the scripts page you have been refering to, thank you.

Re: Switch something with sensor values

Posted: Sunday 09 May 2021 22:51
by psubiaco
It's not easy to write good documentation... often people search for info in various post, then when they find the right answer that solve their problem, they forget to share that answer in other threads, so another people looking for that answer also needs to read several threads before finding the right answer. This is the life...
I can renew my invite to learn scripting... maybe it's not trivial, but it's very useful!!
Regards.
Paolo