Page 1 of 1
group.state not on / mixed
Posted: Thursday 13 September 2018 10:51
by terrorsource
Hi,
I'm trying to make a dzvents script based on a group of lights.
I want to switch "Slapen" on when all lights are off between nighttime.
Is it possible to get the status "Mixed" of a group?
I now have a script based on "group.state == 'Off'" but "On" should not work because not all lights are on at once.
Can i set "group.state == 'Mixed" ? It is not stated in the wiki.
Re: group.state not on / mixed
Posted: Thursday 13 September 2018 11:07
by waaren
terrorsource wrote: ↑Thursday 13 September 2018 10:51
Hi,
I'm trying to make a dzvents script based on a group of lights.
I want to switch "Slapen" on when all lights are off between nighttime.
Is it possible to get the status "Mixed" of a group?
I now have a script based on "group.state == 'Off'" but "On" should not work because not all lights are on at once.
Can i set "group.state == 'Mixed" ? It is not stated in the wiki.
Yes,
Code: Select all
return {
on = { devices = { "triggerDevice" }}, -- Change for your triggerDevice
logging = { level = domoticz.LOG_DEBUG,
marker = "Check Group state" },
execute = function(dz)
myGroup = dz.groups("All active devices") -- Change for your group
if myGroup.state == "Mixed" then
dz.log("state of group " .. myGroup.name .. " ===>> " .. myGroup.state,dz.LOG_DEBUG)
else
dz.log("state of group " .. myGroup.name .. " ===>> " .. myGroup.state,dz.LOG_DEBUG)
end
end
}
Re: group.state not on / mixed
Posted: Thursday 13 September 2018 13:18
by terrorsource
waaren wrote: ↑Thursday 13 September 2018 11:07
Yes,
I've now created this, but it is not sending a message via Prowl when the status of the Group changes.
Code: Select all
return {
on = {
groups = { 'AlleLampenHuis' }
},
execute = function(dz)
myGroup = dz.groups("AlleLampenHuis") -- Change for your group
if myGroup.state == "Mixed" and domoticz.devices("Thuis").state == "Off" then
-- domoticz.devices("Slapen").switchOff().checkFirst()
domoticz.notify("State=MIXED","State=MIXED.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)
elseif myGroup.state == "Off" and domoticz.devices("Thuis").state == "Off" then
-- domoticz.devices("Slapen").switchOn().checkFirst()
domoticz.notify("State=OFF","State=OFF.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)
elseif myGroup.state == "On" and domoticz.devices("Thuis").state == "Off" then
-- domoticz.devices("Slapen").switchOff().checkFirst()
domoticz.notify("State=ON","State=ON.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)
end
end
}
Re: group.state not on / mixed
Posted: Thursday 13 September 2018 17:31
by waaren
terrorsource wrote:waaren wrote: ↑Thursday 13 September 2018 11:07
Yes,
I've now created this, but it is not sending a message via Prowl when the status of the Group changes.
Try change all "dz" to "domoticz" or vice versa.
Verstuurd vanaf mijn ONEPLUS A3003 met Tapatalk
Re: group.state not on / mixed
Posted: Thursday 13 September 2018 20:25
by terrorsource
waaren wrote: ↑Thursday 13 September 2018 17:31
terrorsource wrote:waaren wrote: ↑Thursday 13 September 2018 11:07
Yes,
I've now created this, but it is not sending a message via Prowl when the status of the Group changes.
Try change all "dz" to "domoticz" or vice versa.
Verstuurd vanaf mijn ONEPLUS A3003 met Tapatalk
Still not working. I've even cleaned up the script but it is not sending messages. Looks like it's never triggered.
Now have only 1 switch in the group, a dummy switch. when i toggle it nothing happens.
Code: Select all
return {
on = {
groups = { 'AlleLampenHuis' }
},
execute = function(domoticz, group)
myGroup = domoticz.groups("AlleLampenHuis")
if myGroup.state == "Mixed" then
domoticz.notify("State=MIXED","State=MIXED.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)
elseif myGroup.state == "Off" then
domoticz.notify("State=OFF","State=OFF.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)
elseif myGroup.state == "On" then
domoticz.notify("State=ON","State=ON.", domoticz.PRIORITY_NORMAL,nil,nil,domoticz.NSS_PROWL)
end
end
}
Re: group.state not on / mixed
Posted: Thursday 13 September 2018 21:21
by waaren
terrorsource wrote: ↑Thursday 13 September 2018 20:25
waaren wrote: ↑Thursday 13 September 2018 17:31
terrorsource wrote:
I've now created this, but it is not sending a message via Prowl when the status of the Group changes.
Try change all "dz" to "domoticz" or vice versa.
Still not working. I've even cleaned up the script but it is not sending messages. Looks like it's never triggered.
Now have only 1 switch in the group, a dummy switch. when i toggle it nothing happens.
The script in its current form will only execute when the group is switched On or Off. State changes of any device in the group will not trigger it.
domoticz simply does not create a group level event for it and dzVents is therefore not aware anything changed on the grouplevel.
If you want to have the script triggered on any groupdevice change you will have to add these devices in the "on = devices" section
Code: Select all
on = { devices = { "groupdevice1, groupdevice2 , ... groupdevice99" }},
what might help is that these devicenames can be entered in a wildcard form e.g. group*
Re: group.state not on / mixed
Posted: Friday 14 September 2018 9:28
by terrorsource
waaren wrote: ↑Thursday 13 September 2018 21:21
terrorsource wrote: ↑Thursday 13 September 2018 20:25
waaren wrote: ↑Thursday 13 September 2018 17:31
Try change all "dz" to "domoticz" or vice versa.
Still not working. I've even cleaned up the script but it is not sending messages. Looks like it's never triggered.
Now have only 1 switch in the group, a dummy switch. when i toggle it nothing happens.
The script in its current form will only execute when the group is switched On or Off. State changes of any device in the group will not trigger it.
domoticz simply does not create a group level event for it and dzVents is therefore not aware anything changed on the grouplevel.
If you want to have the script triggered on any groupdevice change you will have to add these devices in the "on = devices" section
Code: Select all
on = { devices = { "groupdevice1, groupdevice2 , ... groupdevice99" }},
what might help is that these devicenames can be entered in a wildcard form e.g. group*
The last script is just for test purposes only.
Want to have it send a message when the group has changed (ON/OFF/Mixed).
From there on i can switch "Sleeping" on and create an alarm for motion and doors.
Re: group.state not on / mixed
Posted: Saturday 15 September 2018 21:48
by waaren
terrorsource wrote: ↑Friday 14 September 2018 9:28
The last script is just for test purposes only.
Want to have it send a message when the group has changed (ON/OFF/Mixed).
From there on i can switch "Sleeping" on and create an alarm for motion and doors.
Maybe this other approach can help you achieving what you want. It will notify you within a minute after a group state change happens by a device in that group or imediate when the group itself was changed manual of via a command.
When executed the first time it will also send 1 notification
Code: Select all
local groupName = "AlleLampenHuis"
return {
on = {
groups = { groupName },
timer = { "every minute" },
httpResponses = { "getSceneState" }},
logging = {
level = domoticz.LOG_INFO,
marker = "getSceneState"
},
data = { state = { initial = "" }},
execute = function(dz, item)
local myGroup = dz.groups(groupName)
local function triggerJSON()
local urlString = dz.settings['Domoticz url'] .. "/json.htm?type=scenes"
dz.openURL({ url = urlString,
method = "GET",
callback = "getSceneState" })
end
local function getState(groupName)
local state = "No state found for " .. groupName
if item.json.result ~= nil then
rt = item.json.result
else
dz.log("No values found",dz.LOG_DEBUG )
return
end
for i=1,#rt do -- Loop through the result
dz.log( "Checking group " .. rt[i].idx .. " ===>> " .. rt[i].Name ,dz.LOG_DEBUG)
if rt[i].Name == groupName then
return rt[i].Status
end
end
return state
end
if item.isHTTPResponse then
myGroup.state = getState(groupName)
if myGroup.state ~= dz.data.state then
dz.data.state = myGroup.state
dz.log("State changed to " .. myGroup.state, dz.LOG_FORCE)
dz.notify("State=" .. myGroup.state ,"State=" .. myGroup.state, dz.PRIORITY_NORMAL,nil,nil,dz.NSS_PROWL)
else
dz.log("State of : " .. myGroup.name .. " is still " .. myGroup.state, dz.LOG_DEBUG)
end
else
triggerJSON()
end
end
}
Re: group.state not on / mixed
Posted: Monday 24 September 2018 11:36
by terrorsource
waaren wrote: ↑Saturday 15 September 2018 21:48
terrorsource wrote: ↑Friday 14 September 2018 9:28
The last script is just for test purposes only.
Want to have it send a message when the group has changed (ON/OFF/Mixed).
From there on i can switch "Sleeping" on and create an alarm for motion and doors.
Maybe this other approach can help you achieving what you want. It will notify you within a minute after a group state change happens by a device in that group or imediate when the group itself was changed manual of via a command.
When executed the first time it will also send 1 notification
Thanks for the script. i've extended it a bit further.
This is the result:
Code: Select all
local groupName = "AlleLampenHuis"
return {
on = {
groups = { groupName },
timer = { "every minute between nighttime and 05:00", "at 05:01" },
httpResponses = { "getSceneState" }},
logging = {
level = domoticz.LOG_INFO,
marker = "getSceneState"
},
data = { state = { initial = "" }},
execute = function(dz, item)
local myGroup = dz.groups(groupName)
local function triggerJSON()
local urlString = dz.settings['Domoticz url'] .. "/json.htm?type=scenes"
dz.openURL({ url = urlString,
method = "GET",
callback = "getSceneState" })
end
local function getState(groupName)
local state = "No state found for " .. groupName
if item.json.result ~= nil then
rt = item.json.result
else
dz.log("No values found",dz.LOG_DEBUG )
return
end
for i=1,#rt do -- Loop through the result
dz.log( "Checking group " .. rt[i].idx .. " ===>> " .. rt[i].Name ,dz.LOG_DEBUG)
if rt[i].Name == groupName then
return rt[i].Status
end
end
return state
end
if item.isHTTPResponse then
myGroup.state = getState(groupName)
if domoticz.time.matchesRule("at 05:01") then
dz.devices("Slapen").switchOff().checkFirst()
dz.notify("Slaapstand=OFF","Slaapstand is uitgezet.", dz.PRIORITY_NORMAL,nil,nil,dz.NSS_PROWL)
elseif myGroup.state ~= dz.data.state then
dz.data.state = myGroup.state
if dz.data.state == "Off" and dz.devices("Thuis").state == "On" then
dz.devices("Slapen").switchOn().checkFirst()
dz.notify("Slaapstand=ON","Slaapstand is aangezet.", dz.PRIORITY_NORMAL,nil,nil,dz.NSS_PROWL)
elseif dz.data.state == "On" and dz.devices("Thuis").state == "On" then
dz.devices("Slapen").switchOff().checkFirst()
dz.notify("Slaapstand=OFF","Slaapstand is uitgezet.", dz.PRIORITY_NORMAL,nil,nil,dz.NSS_PROWL)
elseif dz.data.state == "Mixed" and dz.devices("Thuis").state == "On" then
dz.devices("Slapen").switchOff().checkFirst()
dz.notify("Slaapstand=OFF","Slaapstand is uitgezet.", dz.PRIORITY_NORMAL,nil,nil,dz.NSS_PROWL)
end
elseif
dz.log("Status van : " .. myGroup.name .. " is nog steeds: " .. myGroup.state, dz.LOG_DEBUG)
end
else
triggerJSON()
end
end
}