first steps
Moderator: leecollings
-
- Posts: 139
- Joined: Thursday 05 June 2014 10:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: 's-Hertogenbosch, NL
- Contact:
first steps
Just started the first steps in dzvents. Have many switches with a space in the name. Can I use that? Get an error every time.
In the example in the Wiki there is something I do not understand, i see Room switch and roomSwitch is that right?
return {
active = true,
on = {
devices = {
'Room switch'
}
},
execute = function(domoticz, roomSwitch)
if (roomSwitch.state == 'On' and domoticz.devices('Living room').temperature > 18) then
domoticz.devices('Another switch').switchOn()
domoticz.notify('This rocks!',
'Turns out that it is getting warm here',
domoticz.PRIORITY_LOW)
end
end
}
In the example in the Wiki there is something I do not understand, i see Room switch and roomSwitch is that right?
return {
active = true,
on = {
devices = {
'Room switch'
}
},
execute = function(domoticz, roomSwitch)
if (roomSwitch.state == 'On' and domoticz.devices('Living room').temperature > 18) then
domoticz.devices('Another switch').switchOn()
domoticz.notify('This rocks!',
'Turns out that it is getting warm here',
domoticz.PRIORITY_LOW)
end
end
}
-
- Posts: 191
- Joined: Wednesday 26 November 2014 18:43
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: first steps
At the devices you need to enter the device name which you are going to do something with.
The function of just a name i think.
If you put in domoticz. Abc then you need to use Abc for the rest of the script like Abc.state this can be different than the switch name in domoticz.
The function of just a name i think.
If you put in domoticz. Abc then you need to use Abc for the rest of the script like Abc.state this can be different than the switch name in domoticz.
-
- Posts: 139
- Joined: Thursday 05 June 2014 10:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: 's-Hertogenbosch, NL
- Contact:
Re: first steps
Thanks, i give 't a try tomorrow!tlpeter wrote:At the devices you need to enter the device name which you are going to do something with.
The function of just a name i think.
If you put in domoticz. Abc then you need to use Abc for the rest of the script like Abc.state this can be different than the switch name in domoticz.
-
- Posts: 45
- Joined: Thursday 09 February 2017 18:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: first steps
Hi. I'm newby in dzVents too.
How can I use domoticz.devices().forEach(function() .. end) instead of for n, Lamp in pairs(Lamps) do .. end in my script?
Thanks
How can I use domoticz.devices().forEach(function() .. end) instead of for n, Lamp in pairs(Lamps) do .. end in my script?
Code: Select all
return {
active = true,
on = {
devices = {
'PIR'
}
},
logging = {
level = domoticz.LOG_ERROR
},
execute = function(domoticz, switch)
local Lamps = {'Light-1', 'Light-2'}
if (switch.state == 'On') then
for n, Lamp in pairs(Lamps) do
if (domoticz.time.matchesRule('at 06:00-08:00')) then
domoticz.devices(Lamp).dimTo(10)
end
end
end
end
}
-
- Posts: 139
- Joined: Thursday 05 June 2014 10:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: 's-Hertogenbosch, NL
- Contact:
Re: first steps
Yes!! the first (simple) script works.
Code: Select all
return {
active = true,
on = {
devices = {
'Deur Berging',
'Deur berging buiten'
}
},
execute = function(domoticz, DeurBerging)
local DeurBergingBuiten = domoticz.devices('Deur berging buiten')
local LampBerging = domoticz.devices('Lamp berging')
if (DeurBerging.state == 'Open') or (DeurBergingBuiten.state == 'Open') then
LampBerging.switchOn()
else
LampBerging.switchOff().afterSec(15)
end
end
}
-
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: first steps
The documentation should give you examples in how to use the forEach() function. Isn't that helping you?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
- Posts: 45
- Joined: Thursday 09 February 2017 18:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: first steps
Not yet, unfortunately. Can you show in my script example?dannybloe wrote:The documentation should give you examples in how to use the forEach() function. Isn't that helping you?
Thanks
-
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: first steps
Well, in your case you want to loop over your array of lamp names and that is just a standard lua table/array so you loop is perfectly suited for that. dzVents forEach is if want to loop over all devices or over a set of filtered devices (or over any of the dzVents collections). But in your situstion that is not the case. So I wouldn't change your code.
What I would change is restrict your code differently to the time-frame you wish your PIR to be active. Now you check the current time inside the loop over and over again while all you need to do is:
And remove the check in your execute function.
What I would change is restrict your code differently to the time-frame you wish your PIR to be active. Now you check the current time inside the loop over and over again while all you need to do is:
Code: Select all
devices = { ['PIR'] = 'at 06:00-08:00' }
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
- Posts: 45
- Joined: Thursday 09 February 2017 18:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: first steps
Means in my case all is correct.dannybloe wrote:Well, in your case you want to loop over your array of lamp names and that is just a standard lua table/array so you loop is perfectly suited for that. dzVents forEach is if want to loop over all devices or over a set of filtered devices (or over any of the dzVents collections). But in your situstion that is not the case. So I wouldn't change your code.
What I would change is restrict your code differently to the time-frame you wish your PIR to be active. Now you check the current time inside the loop over and over again while all you need to do is:
And remove the check in your execute function.Code: Select all
devices = { ['PIR'] = 'at 06:00-08:00' }
I use "domoticz.time.matchesRule" function as a condition for turn on a group of lamps at different times with different brightness.
Special thanks for the dzVents!
-
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: first steps
I don't agree. Your if is executed for all lamps in your array. There is no need to evaluate the rule inside your loop as the result is the same for every loop iteration. That's why you can remove it from the loop and do it before the loop. If it evaluates to false there is no need for your loop in the first place. And moving it to the on-section is even better as it won't end up in your log as well as dzVents won't even call your execute function if it doesn't match the time rule.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
- Posts: 45
- Joined: Thursday 09 February 2017 18:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Contact:
Re: first steps
I'm sorry. That was part of the scriptdannybloe wrote:I don't agree. Your if is executed for all lamps in your array. There is no need to evaluate the rule inside your loop as the result is the same for every loop iteration. That's why you can remove it from the loop and do it before the loop. If it evaluates to false there is no need for your loop in the first place. And moving it to the on-section is even better as it won't end up in your log as well as dzVents won't even call your execute function if it doesn't match the time rule.
- Spoiler: show
-
- Posts: 139
- Joined: Thursday 05 June 2014 10:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: 's-Hertogenbosch, NL
- Contact:
Re: first steps
I get on my way slowly. Have already made various scripts and blocky's.
Pushover also works but I have a question about how I get telegram (bone) method working.
Does this work in the same way as in SH?
curl --data chat_id=19959367 --data-urlencode "text=Some complex text $25 78%" "https://api.telegram.org/bot_mijn code/sendMessage?chat_id=Mijn_id&text=Er is aangebeld!"
Pushover also works but I have a question about how I get telegram (bone) method working.
Does this work in the same way as in SH?
curl --data chat_id=19959367 --data-urlencode "text=Some complex text $25 78%" "https://api.telegram.org/bot_mijn code/sendMessage?chat_id=Mijn_id&text=Er is aangebeld!"
-
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: first steps
Please start a seperate topic for this.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Who is online
Users browsing this forum: No registered users and 1 guest