Behavior of last seen from philips hue motion

Xiaomi, Ikea TRÅDFRI, Philips Hue and more.

Moderator: leecollings

Post Reply
RezaRose
Posts: 65
Joined: Sunday 09 February 2020 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

Behavior of last seen from philips hue motion

Post by RezaRose »

Can somebody explain what is happening?

I have a Philips hue outdoor motion sensor connected to my Zigate. I wanted to write a script with dzvents that turns the lights off after 5 min no motion. But if i use devices.lastupdate the devices.lastupdate resets after 4 minutes, even when there is no motion. Sometimes the device announces himself again after 4 min. I watched the log from last night, and a couple times the counter got to 5 of 9 min. But most of the time it only get till 4 min.

The cooldown for the motion sensor is 5 min. So if i write a script with lights off after 4 and we stay outside longer then that the lights go out for a minute, before motion is detected again. :lol:

Mayby i can get creative with a variable, but i like to know why it is behaving like this.

Daytime:
Spoiler: show
2021-02-02 09:42:00.164 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:42:00.183 Status: dzVents: Buitensensor updated 3 minutes ago
2021-02-02 09:42:00.183 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:42:00.183 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:42:01.532 Status: Python Plugin System: (Zigate USB TLL) Device Annoucement: Buitensensor NwkId: 2940 Ieee: 001788010648e908 MacCap: 80
2021-02-02 09:43:00.167 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:43:00.186 Status: dzVents: Buitensensor updated 4 minutes ago
2021-02-02 09:43:00.186 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:43:00.186 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:44:00.231 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:44:00.250 Status: dzVents: Buitensensor updated 0 minutes ago
2021-02-02 09:44:00.250 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:44:00.251 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:45:00.226 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:45:00.246 Status: dzVents: Buitensensor updated 1 minutes ago
2021-02-02 09:45:00.246 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:45:00.246 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:46:00.262 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:46:00.280 Status: dzVents: Buitensensor updated 2 minutes ago
2021-02-02 09:46:00.280 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:46:00.280 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:46:35.144 Status: Python Plugin System: (Google Nest) Updated 5 units for 1 device(s)
2021-02-02 09:47:00.214 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:47:00.233 Status: dzVents: Buitensensor updated 3 minutes ago
2021-02-02 09:47:00.233 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:47:00.233 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:48:00.283 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:48:00.301 Status: dzVents: Buitensensor updated 4 minutes ago
2021-02-02 09:48:00.301 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:48:00.301 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:49:00.295 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:49:00.317 Status: dzVents: Buitensensor updated 0 minutes ago
2021-02-02 09:49:00.317 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:49:00.317 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:50:00.296 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:50:00.315 Status: dzVents: Buitensensor updated 1 minutes ago
2021-02-02 09:50:00.315 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:50:00.315 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:51:00.281 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:51:00.299 Status: dzVents: Buitensensor updated 2 minutes ago
2021-02-02 09:51:00.299 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:51:00.299 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:51:35.286 Status: Python Plugin System: (Google Nest) Updated 5 units for 1 device(s)
2021-02-02 09:52:00.332 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:52:00.350 Status: dzVents: Buitensensor updated 3 minutes ago
2021-02-02 09:52:00.350 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:52:00.351 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:53:00.360 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:53:00.387 Status: dzVents: Buitensensor updated 4 minutes ago
2021-02-02 09:53:00.387 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:53:00.387 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:54:00.349 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:54:00.370 Status: dzVents: Buitensensor updated 0 minutes ago
2021-02-02 09:54:00.370 Status: dzVents: Tuinverlichting state is Off
2021-02-02 09:54:00.370 Status: dzVents: Info: ------ Finished Buiten verlichting uit bij geen beweging
2021-02-02 09:55:00.321 Status: dzVents: Info: ------ Start internal script: Buiten verlichting uit bij geen beweging:, trigger: "every 1 minutes"
2021-02-02 09:55:00.339 Status: dzVents: Buitensensor updated 1 minutes ago
2021-02-02 09:55:00.339 Status: dzVents: Tuinverlichting state is Off
Raspberry Pi 4 - Raspbian bullseye - Python 3.9 - stable
Dashticz on apache2 - Mqqt - node red
Zigate - USB Tll - Philips hue - Ikea - Innr - Xiaomi - TPlink - Nest -v3
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Behavior of last seen from philips hue motion

Post by waaren »

RezaRose wrote: Tuesday 02 February 2021 10:29 Can somebody explain what is happening?
When looking for help here on a script related issue, please always include both the complete script (obscure any sensitive stuff) and the loglines.
Thx
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
RezaRose
Posts: 65
Joined: Sunday 09 February 2020 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

Re: Behavior of last seen from philips hue motion

Post by RezaRose »

waaren wrote: Tuesday 02 February 2021 10:59
RezaRose wrote: Tuesday 02 February 2021 10:29 Can somebody explain what is happening?
When looking for help here on a script related issue, please always include both the complete script (obscure any sensitive stuff) and the loglines.
Thx
The script is working fine, it only shows what is happening with the device last update status. I think it is more a zigate or device related.
But for the one who wants to know:

Code: Select all

return {
       on = {
          timer = {
             'every 1 minutes'
          }
       },
      	execute = function(dz, timer)
      	    
      	local Tuinverlichting = dz.groups('Tuinverlichting')
      	local Buitensensor = dz.devices('Buitensensor')
      	
      	print('Buitensensor updated ' .. Buitensensor.lastUpdate.minutesAgo .. ' minutes ago')
      	
      	
		if Buitensensor.lastUpdate.minutesAgo >= 4  and (Tuinverlichting.state == 'On' or Tuinverlichting.state == 'Mixed')   then
		    
                Tuinverlichting.switchOff()
                    print('Tuinverlichting is switched off')
                    

        else
                 
                 print('Tuinverlichting state is ' .. Tuinverlichting.state)
	    end
    end
    }
Raspberry Pi 4 - Raspbian bullseye - Python 3.9 - stable
Dashticz on apache2 - Mqqt - node red
Zigate - USB Tll - Philips hue - Ikea - Innr - Xiaomi - TPlink - Nest -v3
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Behavior of last seen from philips hue motion

Post by waaren »

RezaRose wrote: Tuesday 02 February 2021 11:17 The script is working fine, it only shows what is happening with the device last update status. I think it is more a zigate or device related.
Thx for sharing.

Could it be that the motion sensor reacts to the light?
Most motion sensors change state when motion is detected AND they change state after the set timeout period. In domoticz this will update the lastUpdate field in both cases.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
RezaRose
Posts: 65
Joined: Sunday 09 February 2020 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

Re: Behavior of last seen from philips hue motion

Post by RezaRose »

I will check the log again tomorrow. It can make the difference between day and night maybe that is the way he does that..
Raspberry Pi 4 - Raspbian bullseye - Python 3.9 - stable
Dashticz on apache2 - Mqqt - node red
Zigate - USB Tll - Philips hue - Ikea - Innr - Xiaomi - TPlink - Nest -v3
RezaRose
Posts: 65
Joined: Sunday 09 February 2020 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

Re: Behavior of last seen from philips hue motion

Post by RezaRose »

It seems like at night time the sensor get updates every 5 min or longer. Too bad i can use that value.
Raspberry Pi 4 - Raspbian bullseye - Python 3.9 - stable
Dashticz on apache2 - Mqqt - node red
Zigate - USB Tll - Philips hue - Ikea - Innr - Xiaomi - TPlink - Nest -v3
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: Behavior of last seen from philips hue motion

Post by erem »

here is a different approach

use the dzVent data function to detect the last switch on.

i wrote this script to detect the absence of movement, but you should get the general idea.
Spoiler: show

Code: Select all

-- ************************************************************************
-- Motion      - Process the motion detector. If no Motion is detected 
--               while someone is home send out an alarm.            
--               When no motion is detected for period grace1, send out 
--               an e-mail to Rob. If no motion is detected for period grace2
--               send out an e-mail to xxxx and yyyy
--               
--
-- Programmer: R. Muller  
-- date 2019-02-25
--
-- Version     date        Programmer  Reasom
-- ==========  ==========  ==========  ===================================
-- 1.0.0       2019-02-25  RM          Initial release
-- 1.0.1       2019-10-02  RM          rewritten for RCWP-0516 sensor
--
-- ************************************************************************

return {
	on = {
          devices = {
	     'DopplerSensor'  -- Motion sensor switch  
	  },
	  timer = {'every minute'}
	},
	data = {
	    msg1sent = { initial = 1 },
	    msg2sent = { initial = 1 },
            Motion = { history = true, maxItems = 100, maxMinutes = 40 } -- declare list
        },
        execute = function(domoticz, item)
	    
	    local grace1 = '00:10:00'       -- periode waarna een alert naar Rob gaat (hh:mm:ss)
	    local grace2 = '00:15:00'       -- periode waarna een alert naar xxxx en yyyy gaat (hh:mm:ss)
	    local email1 = '[email protected]'
	    local email2 = '[email protected]'
	        
	    --print('Motion Script Running')

	    if (domoticz.devices('iPhone-R').state  == 'On' and  -- R Home
	        domoticz.devices('iPhone-M').state == 'Off')  then  -- M Away
	        
              print('domoticz.data.msg1sent at start: '  .. domoticz.data.msg1sent)
              print('domoticz.data.msg2sent at start: '  .. domoticz.data.msg2sent)	        
	                
              if (item.isDevice) then
                print('Inside item.isDevice: Device name = ' .. item.name .. ' Device state = ' .. item.state)
                -- motion detected, so reset message counters
                domoticz.data.msg1sent = 0
                domoticz.data.msg2sent = 0
                -- store current device status in data table for later retieval
                if (item.state == "On") then
                  domoticz.data.Motion.add(tonumber('1'))
                else
                  domoticz.data.Motion.add(tonumber('0'))
                end
        
            elseif (item.isTimer) then
               print('Inside isTimer')	
               if (domoticz.data.Motion.maxSince(grace1) == nil) then   -- no data found in last grace1 minutes
                 print('domoticz.data.Motion.maxSince: nil found as value, no data to process')
               else
                 print('domoticz.data.Motion.maxSince: '  .. domoticz.data.Motion.maxSince(grace1))
               end
	                    
               if ( (domoticz.data.Motion.maxSince(grace1) == 0    or 
                     domoticz.data.Motion.maxSince(grace1) == nil) and 
                    (domoticz.data.msg1sent == 0  or
                     domoticz.data.msg1sent == nil ) ) then
                 print('Action required send message to email1 (Rob)')  
                 domoticz.log('No Motion detected for ' .. grace1 .. ' minutes, sending alert to Rob', domoticz.LOG_INFO)
                 domoticz.data.msg1sent = 1 -- message sent indicator
                 print('domoticz.data.msg1sent (s/b 1): '  .. domoticz.data.msg1sent)
                 -- send message to rob
                 domoticz.email('Reageer!!', 'De computer heeft Rob al ' .. grace1 .. ' minuten niet gezien', email1 )
               end --  if (domoticz.data.Motion.maxSince(grace1) = 0 
                   
               if ( (domoticz.data.Motion.maxSince(grace2) == 0 or
                     domoticz.data.Motion.maxSince(grace2) == nil ) and 
                    (domoticz.data.msg1sent == 1 and 
                     domoticz.data.msg2sent == 0) ) then
                  print('Action required send data to email2 (Marianne en Paul)') 
                  domoticz.log('No Motion detected for ' .. grace2 ..' minutes, sending alert', domoticz.LOG_INFO)
                  domoticz.data.msg2sent = 1 -- message2 sent indicator
                  print('domoticz.data.msg2sent (s/b 1): '  .. domoticz.data.msg2sent)
                  -- send message to paul en marianne
                  domoticz.email('Geen beweging van Rob', 'De computer heeft Rob al ' .. grace2 .. ' minuten niet gezien', email2 )
                end --  if (domoticz.data.Motion.maxSince(grace2) = 0 
	                    
              end -- if (item.IsDevice )
	   end  -- if domoticz.devices('iPhone-R').state == 'On' 
	   --print('Motion Script Ending')
         end -- function(domoticz, item)
}

Regards,

Rob
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Behavior of last seen from philips hue motion

Post by waaren »

erem wrote: Wednesday 03 February 2021 19:00 here is a different approach..
Maybe I am overlooking something but to solve the gardenlight/ motion issue of @RezaRose it should be possible to just code it like below.
assuming the initial state is that the garden lights are On / Mixed.

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Buitensensor',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'motion',
    },

    execute = function(dz, item)
        local lights = dz.groups('Tuinverlichting')
        local timeout = 300 -- timeout in seconds

        if item.active and lights.state ~= 'Off' then
            lights.switchOff().afterSec(timeout) -- this is also an implicit cancelQueuedCommands() for this device 
        end
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
RezaRose
Posts: 65
Joined: Sunday 09 February 2020 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

Re: Behavior of last seen from philips hue motion

Post by RezaRose »

I have tried your version. With .afterMinutes. It does not work properly because it only activates when the sensor is detecting motion.

Maybe i can fix it with a variable that update +1 when te timer get on 4 min or above. And if the variable gets on 2 the lights go off. So that is between 5 or 8 min then. And that is fine.
Raspberry Pi 4 - Raspbian bullseye - Python 3.9 - stable
Dashticz on apache2 - Mqqt - node red
Zigate - USB Tll - Philips hue - Ikea - Innr - Xiaomi - TPlink - Nest -v3
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Behavior of last seen from philips hue motion

Post by waaren »

RezaRose wrote: Wednesday 03 February 2021 21:37 I have tried your version. With .afterMinutes. It does not work properly because it only activates when the sensor is detecting motion.
OK.

Below version will also be triggered when the group is switched.

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Buitensensor',
        },
        groups =
        {
            'Tuinverlichting',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'motion',
    },

    execute = function(dz, item)
        local lights = dz.groups('Tuinverlichting')
        local sensor = dz.devices('Buitensensor')

        local timeout = 300 -- timeout in seconds

        if item.state ~= 'Off' and lights.state ~= 'Off' then
            lights.switchOff().afterSec(timeout) -- this is also an implicit cancelQueuedCommands() for this device 
        end
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest