group.state not on / mixed

Easy to use, 100% Lua-based event scripting framework.
Post Reply
terrorsource
Posts: 53
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

group.state not on / mixed

Post by terrorsource » 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.

User avatar
waaren
Posts: 931
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: group.state not on / mixed

Post by waaren » Thursday 13 September 2018 11:07

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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

terrorsource
Posts: 53
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: group.state not on / mixed

Post by terrorsource » Thursday 13 September 2018 13:18

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
}

User avatar
waaren
Posts: 931
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: group.state not on / mixed

Post by waaren » 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

Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

terrorsource
Posts: 53
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: group.state not on / mixed

Post by terrorsource » Thursday 13 September 2018 20:25

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
}

User avatar
waaren
Posts: 931
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: group.state not on / mixed

Post by waaren » Thursday 13 September 2018 21:21

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*
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

terrorsource
Posts: 53
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: group.state not on / mixed

Post by terrorsource » Friday 14 September 2018 9:28

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.

User avatar
waaren
Posts: 931
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: group.state not on / mixed

Post by waaren » 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

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
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest