Doorswitch to turn on and off a light Topic is solved

Moderator: leecollings

dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Doorswitch to turn on and off a light

Post by dutchronnie »

Hello

I have the following problem.

I have a doorswitch installed in Domoticz.
I installed with this youtube video https://www.youtube.com/watch?v=Oq-hN-RJ2sA

The switch is working with the following code to turn on the light.

Code: Select all

return {
	active = true,
	on = {
		devices = { 
			['Achterdeur'] = { 'at nighttime' }
		}
	},
	execute = function(domoticz, door)
		local light = domoticz.devices('Buitenlamp achter')
      
		if (door.state == 'Open') then
			light.switchOn()
		end
	end
}

But when the door is closed i want to turn off the light, but it doesn't work.
It looks like the only state of the door is open.

I used the following code to turn off the light.

Code: Select all

return {
	active = true,
	on = {
		devices = { 
			['Achterdeur'] = { 'at nighttime' }
		}
	},
	execute = function(domoticz, door)
		local light = domoticz.devices('Buitenlamp achter')
      
		if (door.state == 'closed') then
			light.switchOff().afterSec(10)
		end
	end
}
I hope someone can tell me what i am doing wrong.
mosjonathan
Posts: 40
Joined: Friday 24 February 2017 21:20
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by mosjonathan »

Your device is only sending on i think.
The log what is received would be helpfull
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Doorswitch to turn on and off a light

Post by dutchronnie »

Code: Select all

2020-01-04 18:56:19.727 Status: dzVents: Info: ------ Start internal script: Script #2: Device: "Achterdeur (RFLink Gateway)", Index: 33
2020-01-04 18:56:19.727 Status: dzVents: Debug: Script #2: State of Achterdeur is Open
2020-01-04 18:56:19.727 Status: dzVents: Debug: Script #2: nValue Achterdeur is 1
2020-01-04 18:56:19.727 Status: dzVents: Debug: Script #2: sValue Achterdeur is Open
2020-01-04 18:56:19.727 Status: dzVents: Debug: Script #2: type of Achterdeur is Light/Switch
2020-01-04 18:56:19.727 Status: dzVents: Debug: Script #2: subType of Achterdeur is EV1527
2020-01-04 18:56:19.728 Status: dzVents: Debug: Script #2: Level Achterdeur is 0
2020-01-04 18:56:19.728 Status: dzVents: Debug: Script #2: levelName of Achterdeur is NA
2020-01-04 18:56:19.728 Status: dzVents: Info: Script #2: ------ Finished Script #2
It looks like that that there is only an open signal.
I closed the door but i don't see anything in the log, But the state on the domoticz dashboard is changed.
When the door is opened, then on the dashboard it says it is open, when i close the door, the state on the dashboard says "closed" after some time
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by waaren »

dutchronnie wrote: Saturday 04 January 2020 18:26 The switch is working with the following code to turn on the light.
But when the door is closed i want to turn off the light, but it doesn't work.
I hope someone can tell me what i am doing wrong.
I guess it has to do with case. Close is not equal to close.

But why guessing ? Can you try below script ?

Code: Select all

return {
    active = true,
    on = {
        devices = { 
            ['Achterdeur'] = { 'at nighttime' },
        },
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
    },
    
    execute = function(domoticz, door)
        _G.logMarker = _G.moduleLabel
        local light = domoticz.devices('Buitenlamp achter')
        
        dz.log('state of ' .. door.name .. ': ' .. door.state )
        
        if (door.state == 'Open') then
            light.switchOn()
        else
            light.switchOff().afterSec(10)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Doorswitch to turn on and off a light

Post by dutchronnie »

I tried the script, but get the following error:

2020-01-04 19:58:10.321 Error: dzVents: Error: (2.5.3) error loading module 'test' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/test.lua':
2020-01-04 19:58:10.321 ...e/pi/domoticz/scripts/dzVents/generated_scripts/test.lua:14: '}' expected (to close '{' at line 1) near 'execute'

But i can not find the error

I also changed the case to Closed, but that didn't also help
Last edited by dutchronnie on Saturday 04 January 2020 20:06, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by waaren »

dutchronnie wrote: Saturday 04 January 2020 20:00 2020-01-04 19:58:10.321 ...e/pi/domoticz/scripts/dzVents/generated_scripts/test.lua:14: '}' expected (to close '{' at line 1) near 'execute'
But i can not find the error
My suggested script missed a comma. Corrected that now. Can you reload and try again ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Doorswitch to turn on and off a light

Post by dutchronnie »

This are the results of your script in the log file:
  • 2020-01-04 20:10:10.349 Status: dzVents: Info: Handling events for: "Achterdeur", value: "Open"
    2020-01-04 20:10:10.349 Status: dzVents: Info: ------ Start internal script: test: Device: "Achterdeur (RFLink Gateway)", Index: 33
    2020-01-04 20:10:10.351 Status: dzVents: Debug: test: Processing device-adapter for Buitenlamp achter: Switch device adapter
    2020-01-04 20:10:10.352 Status: dzVents: Info: test: ------ Finished test
    2020-01-04 20:10:10.351 Error: dzVents: Error: (2.5.3) test: An error occurred when calling event handler test
    2020-01-04 20:10:10.351 Error: dzVents: Error: (2.5.3) test: ...e/pi/domoticz/scripts/dzVents/generated_scripts/test.lua:18: attempt to index a nil value (global 'dz')
The device 'Buitenlamp achter' didn't switch on
mosjonathan
Posts: 40
Joined: Friday 24 February 2017 21:20
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by mosjonathan »

If i watch the YouTube video that you attached i see that there are 2 devices discovered.
One for door open and one for door closed.
They only send a on command.
I would suggest that you revert wat you did acording to the video.

Then you click in the green arrow to get those devices in the switches tab.
Convert them to push on.
Make a script what listens to the devices and make the actions based on that.
You could also make a extra dummy switch to reflect de door status
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Doorswitch to turn on and off a light

Post by dutchronnie »

I i do that, the result is as follows:

when i switch the doorcontact there a 2 devices detected by rflink. They have both the same id number in domoticz but different unit numbers.
When i add them to domoticz, and switch the doorcontact nothing happens, the state of both don't change.

In mine opinion i can not use this.
mosjonathan
Posts: 40
Joined: Friday 24 February 2017 21:20
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by mosjonathan »

Did you add them? The green arrow is blue?

If yes check the log of the switch Every time you open or close it should say on with a time stamp
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Doorswitch to turn on and off a light

Post by dutchronnie »

Yes, both are in the log.
(I used another switch, called deur 1 and deur 2)

2020-01-04 22:22:57.449 (RFLink Gateway) Light/Switch (deur 2)
2020-01-04 22:23:40.307 (RFLink Gateway) Light/Switch (deur 1)
mosjonathan
Posts: 40
Joined: Friday 24 February 2017 21:20
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by mosjonathan »

What is the state they are reporting when you open and close the door?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by waaren »

dutchronnie wrote: Saturday 04 January 2020 22:25 Yes, both are in the log.
(I used another switch, called deur 1 and deur 2)

2020-01-04 22:22:57.449 (RFLink Gateway) Light/Switch (deur 2)
2020-01-04 22:23:40.307 (RFLink Gateway) Light/Switch (deur 1)
Can you try this ?

Code: Select all

return {
    active = true,
    on = {
        devices = { 
            ['Achterdeur'] = { 'at nighttime' },
            ['deur 1'] = { 'at nighttime' },
            ['deur 2'] = { 'at nighttime' },            
        },
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
    },
    
    execute = function(domoticz, door)
        _G.logMarker = _G.moduleLabel
        local light = domoticz.devices('Buitenlamp achter')
        
        domoticz.log('state of ' .. door.name .. ': ' .. door.state .. ' => ' .. (door.active and ' active' or 'not active') )
        
        if door.active or door.state == 'Open' or door.state == 'On' then
            light.switchOn()
        else
            light.switchOff().afterSec(10)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Doorswitch to turn on and off a light

Post by dutchronnie »

I tried the script, and when i use the switch, the only thing i see in the log is this:

2020-01-05 13:27:53.018 (RFLink Gateway) Light/Switch (deur 2)
2020-01-05 13:27:57.060 (RFLink Gateway) Light/Switch (deur 1)

When i try the doorsensor "Buitendeur" i see this:

2020-01-05 13:37:01.950 Status: dzVents: Info: Handling events for: "Achterdeur", value: "Open"
2020-01-05 13:37:01.950 Status: dzVents: Info: ------ Start internal script: test 1: Device: "Achterdeur (RFLink Gateway)", Index: 33
2020-01-05 13:37:01.953 Status: dzVents: Debug: test 1: Processing device-adapter for Buitenlamp achter: Switch device adapter
2020-01-05 13:37:01.953 Status: dzVents: Info: test 1: state of Achterdeur: Open => active
2020-01-05 13:37:01.953 Status: dzVents: Debug: test 1: Constructed timed-command: On
2020-01-05 13:37:01.953 Status: dzVents: Info: test 1: ------ Finished test 1
2020-01-05 13:37:01.955 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua

The 'Buitenlamp achter' is switched on, but it stays on, en don't switch off after 10 seconds
It looks like there is no state change to close
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by waaren »

dutchronnie wrote: Sunday 05 January 2020 13:40 I tried the script, and when i use the switch, the only thing i see in the log is this:

Code: Select all

2020-01-05 13:27:53.018 (RFLink Gateway) Light/Switch (deur 2)
2020-01-05 13:27:57.060 (RFLink Gateway) Light/Switch (deur 1)
The 'Buitenlamp achter' is switched on, but it stays on, en don't switch off after 10 seconds
It looks like there is no state change to close
Did you change nighttime to daytime in the script ?
if there is no state change for close then you could do a

Code: Select all

switchOn() 
switchOff().afterSec(300) 

on Open or buy a sensor that do report an Off / Close state.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Doorswitch to turn on and off a light

Post by dutchronnie »

Did you change nighttime to daytime in the script ?
if there is no state change for close then you could do a
Yes i did.

I find it very strange.

I found another toppic
https://www.domoticz.com/forum/viewtopi ... 6&start=20
i do have the same sensors so i followed the instuctions, but on the and the behaviour is the same.
I see the switch in the log, door open and door closed
But it is not possible to activate a virtual sensor with the commands
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by waaren »

dutchronnie wrote: Sunday 05 January 2020 15:09 I found another topic
https://www.domoticz.com/forum/viewtopi ... 6&start=20
i do have the same sensors so i followed the instuctions, but on the and the behaviour is the same.
I see the switch in the log, door open and door closed
That explains a lot. These sensors are using a different approach then the standard ones. The open and close states do update separate devices in domoticz. So you now check one device for the open state but try to check the same one for close state and you should check the other device.

In the topic there is a clear description on how to set them up (even with a youtube) and some ready made dzVents scripts.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Doorswitch to turn on and off a light

Post by dutchronnie »

Yes, i have read the whole topic, and have setup everything as they say.
But they use a virtual switch, and the door sensor toggles the virtual switch.

But in mine setup nothing happens.
In the log file i see that door open and door close sensors are activated, but they don't toggle the virtual switch.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Doorswitch to turn on and off a light

Post by waaren »

dutchronnie wrote: Sunday 05 January 2020 18:40 But they use a virtual switch, and the door sensor toggles the virtual switch.

In the log file i see that door open and door close sensors are activated, but they don't toggle the virtual switch.
One last try

Code: Select all

return {
    active = true,
    on = {
        devices = { 
            ['Achterdeur'] = { 'at nighttime' },
            ['deur 1'] = { 'at nighttime' },
            ['deur 2'] = { 'at nighttime' },            
        },
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
    },
    
    execute = function(dz, door)
        _G.logMarker = _G.moduleLabel
        local light = dz.devices('Buitenlamp achter')
        
        open = dz.devices('deur 1')
        closed = dz.devices('deur 2')
        
        dz.log('state of ' .. door.name .. ': ' .. door.state .. ' => ' .. (door.active and ' active' or 'not active') )
        
        if door == open then
            light.switchOn()
        elseif door == closed then
            light.switchOff().afterSec(10)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dutchronnie
Posts: 46
Joined: Thursday 15 August 2013 22:01
Target OS: -
Domoticz version:
Contact:

Re: Doorswitch to turn on and off a light

Post by dutchronnie »

Thanks for all your help.

But it is stil the same.
I see in the log door goes open and door is closed.

but the lamp is not activated.
I have tried with virtual sensors, other lamps in mine configuration, but nothing happens
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest