[SOLVED] DzVents door.state is always open?

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

[SOLVED] DzVents door.state is always open?

Post by Milifax »

Domoticzversion: 3.8152
Platform: RPi 3

A problem which drives me crazy and probably some stupid mistake of myself I overlook.

I have a doorsensor, which switches in Domoticz just fine. It shows the open and closed state.
In DzVents I want to check the state and send a notification when the door is open. Just a standard script.
But the state doesn't change. It is always open. Anyone knows why this could occur?

Code: Select all

--[[

Send a warning when the garage door has been open for more than 10 minutes

 ]]

return {
    active = true,
        on = {
             devices = {
            'Select'
            },
            timer = {
            'every minute'
            }
        },
        execute = function(domoticz)

                local door = domoticz.devices('Achterdeur')
                
                domoticz.log('Deurscript')
                domoticz.log(door.state)
               
                --if (door.state == 'Open' and door.lastUpdate.minutesAgo > 10) then
                --        domoticz.log('Deur is open 5 seconden')
                --        domoticz.notify('Garage door alert', 
                --               'The garage door has been open for more than 10 minutes!',
                --                domoticz.PRIORITY_HIGH)
                --end
        end
}

Code: Select all

2017-08-02 14:20:00.468 dzVents: Info: ------ Start internal script: DoorCheck:, trigger: every minute
2017-08-02 14:20:00.485 dzVents: Info: Deurscript
2017-08-02 14:20:00.485 dzVents: Info: Open
2017-08-02 14:20:00.485 dzVents: Info: ------ Finished DoorCheck
Image
Last edited by Milifax on Friday 04 August 2017 23:52, edited 1 time in total.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: DzVents door.state is always open?

Post by dannybloe »

Can you try to make a trigger for the door in the on-section and see if that does trigger your script when you open or close it? Also, you can create a log-dump of the device and see all attributes (door.dump()). Or you can put dzVents in debugging mode (settings). After dzVents has been triggered it will create a file domoticzData.lua in scripts/dzVents with all the data that Domoticz sent to dzVents. You can inspect that to see what data is set for your door. Please let me know what you can find (and don't forget to turn off debug logging).
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: DzVents door.state is always open?

Post by Milifax »

I'm getting lost ;)

The device is a device with a slave. Maybe that is the strange thing about this device why it can't be detected as swithed.

It only triggers the script on opening the door, not on closing.
I have gone through the dump() and the debug but I cannot find any valua that is changing.
Very strange as I see the Open en Closed in Domoticz changing. It works in Domoticz GUI.

Also when I do a JSON call on the device I see states change. But not in Dzvents (Blocky doesn't switch on it as well)
What I tried for a test is to take action on an on and off state, just in the config of Domoticz.
Also not working. It seems that the state is handled differently as what Domoticz GUI tells me.

The JSON of both states, see InternalState and Data:

Code: Select all

{
   "ActTime" : 1501699751,
   "ServerTime" : "2017-08-02 20:49:11",
   "Sunrise" : "06:04",
   "Sunset" : "21:27",
   "result" : [
      {
         "AddjMulti" : 1.0,
         "AddjMulti2" : 1.0,
         "AddjValue" : 0.0,
         "AddjValue2" : 0.0,
         "BatteryLevel" : 255,
         "CustomImage" : 0,
         "Data" : "Closed",
         "Description" : "",
         "Favorite" : 1,
         "HardwareID" : 12,
         "HardwareName" : "RFLink",
         "HardwareType" : "RFLink Gateway USB",
         "HardwareTypeVal" : 46,
         "HaveDimmer" : false,
         "HaveGroupCmd" : false,
         "HaveTimeout" : false,
         "ID" : "0003B2C0",
         "Image" : "Light",
         "InternalState" : "Closed",
         "IsSubDevice" : true,
         "LastUpdate" : "2017-08-02 20:46:05",
         "Level" : 0,
         "LevelInt" : 0,
         "MaxDimLevel" : 100,
         "Name" : "Achterdeur",
         "Notifications" : "false",
         "PlanID" : "0",
         "PlanIDs" : [ 0 ],
         "Protected" : false,
         "ShowNotifications" : true,
         "SignalLevel" : "-",
         "Status" : "Closed",
         "StrParam1" : "",
         "StrParam2" : "",
         "SubType" : "EV1527",
         "SwitchType" : "Door Contact",
         "SwitchTypeVal" : 11,
         "Timers" : "false",
         "Type" : "Light/Switch",
         "TypeImg" : "door",
         "Unit" : 10,
         "Used" : 1,
         "UsedByCamera" : false,
         "XOffset" : "0",
         "YOffset" : "0",
         "idx" : "82"
      }
   ],
   "status" : "OK",
   "title" : "Devices"
}

Code: Select all

{
   "ActTime" : 1501704557,
   "ServerTime" : "2017-08-02 22:09:17",
   "Sunrise" : "06:04",
   "Sunset" : "21:27",
   "result" : [
      {
         "AddjMulti" : 1.0,
         "AddjMulti2" : 1.0,
         "AddjValue" : 0.0,
         "AddjValue2" : 0.0,
         "BatteryLevel" : 255,
         "CustomImage" : 0,
         "Data" : "Open",
         "Description" : "",
         "Favorite" : 1,
         "HardwareID" : 12,
         "HardwareName" : "RFLink",
         "HardwareType" : "RFLink Gateway USB",
         "HardwareTypeVal" : 46,
         "HaveDimmer" : false,
         "HaveGroupCmd" : false,
         "HaveTimeout" : false,
         "ID" : "0003B2C0",
         "Image" : "Light",
         "InternalState" : "Open",
         "IsSubDevice" : true,
         "LastUpdate" : "2017-08-02 21:51:35",
         "Level" : 0,
         "LevelInt" : 0,
         "MaxDimLevel" : 100,
         "Name" : "Achterdeur",
         "Notifications" : "false",
         "PlanID" : "0",
         "PlanIDs" : [ 0 ],
         "Protected" : false,
         "ShowNotifications" : true,
         "SignalLevel" : "-",
         "Status" : "Open",
         "StrParam1" : "",
         "StrParam2" : "",
         "SubType" : "EV1527",
         "SwitchType" : "Door Contact",
         "SwitchTypeVal" : 11,
         "Timers" : "false",
         "Type" : "Light/Switch",
         "TypeImg" : "door",
         "Unit" : 10,
         "Used" : 1,
         "UsedByCamera" : false,
         "XOffset" : "0",
         "YOffset" : "0",
         "idx" : "82"
      }
   ],
   "status" : "OK",
   "title" : "Devices"
}
I'm now looking in to fetching these JSON call and switch on this data. Not very clean solution I guess.
Eoreh
Posts: 65
Joined: Tuesday 13 October 2015 13:50
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: DzVents door.state is always open?

Post by Eoreh »

Hi !
Check "Locked" and "Unlocked" instead "Open" and "Close". It was change about half year ago for this type of switch.
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: DzVents door.state is always open?

Post by Milifax »

Eoreh wrote:Hi !
Check "Locked" and "Unlocked" instead "Open" and "Close". It was change about half year ago for this type of switch.
I'm not sure what you mean. Where should I check it?
In the JSON output clearly it states Open en Closed.
And if only I could find a statement where I could check it. But none gives me the value the same as the GUI tells me.
Paint
Posts: 10
Joined: Tuesday 11 July 2017 15:47
Target OS: -
Domoticz version:
Contact:

Re: DzVents door.state is always open?

Post by Paint »

Milifax wrote:
Eoreh wrote:Hi !
Check "Locked" and "Unlocked" instead "Open" and "Close". It was change about half year ago for this type of switch.
I'm not sure what you mean. Where should I check it?
In the JSON output clearly it states Open en Closed.
And if only I could find a statement where I could check it. But none gives me the value the same as the GUI tells me.
try the domoticz.devices('NAME').dump()
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: DzVents door.state is always open?

Post by Milifax »

Paint wrote:
try the domoticz.devices('NAME').dump()
As I mentioned above, I did compare the dump(). But I cannot find any changes between the different states.

Is there a way to get the InternalState in Lua? I think I saw in the source it is passed along to Lua.
But dont know how to get and use it.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: DzVents door.state is always open?

Post by dannybloe »

Maybe it is a silent state change that doesn't trigger the event system at all. Have you tried with a classic lua event script? Does that work?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: DzVents door.state is always open?

Post by Milifax »

With my little knowledge of Lua I tried the following code:

Code: Select all

commandArray = {}

print('Lua script active')

    if (devicechanged['Achterdeur'] == 'Open') then
   
        print('Achterdeur triggered')
        print(otherdevices['Achterdeur'])

    end

    if (devicechanged['Achterdeur'] == 'Closed') then
   
        print('Achterdeur triggered Close')
        print(otherdevices['Achterdeur'])

    end


    --Try acting on the Slave device
    if (devicechanged['Achterdeur_Dicht'] == 'Open') then
   
        print('Achterdeur triggered Dicht')
        print(otherdevices['Achterdeur_Dicht'])

    end

    if (devicechanged['Achterdeur_Dicht'] == 'Closed') then
   
        print('Achterdeur triggered Dicht Close')
        print(otherdevices['Achterdeur_Dicht'])

    end

   
return commandArray


The log returns:

Code: Select all

2017-08-03 10:46:08.489 LUA: Lua script active
2017-08-03 10:46:08.692 LUA: Lua script active
2017-08-03 10:46:08.692 LUA: Achterdeur triggered
2017-08-03 10:46:08.692 LUA: Open
2017-08-03 10:46:08.763 LUA: Lua script active
2017-08-03 10:46:08.763 LUA: Achterdeur triggered Dicht
2017-08-03 10:46:08.763 LUA: Open
2017-08-03 10:46:09.421 LUA: Lua script active
2017-08-03 10:46:10.420 LUA: Lua script active
The log only writes when the door is opening. Not when closing.
Also it doens't catch the Closed state.

What is really confusing for me and what I don't understand, is the fact Domoticz gives me a correct Open/Close state in the GUI, but I cannot get the value out of Domoticz.


In a previous post, I mentioned to get the value through a JSON call. However, this also fails as when I use curl to get the data, I get the complete list of all devices and not the specific device mentioned the rid=-parameter I send with it.
In the browser it works to get the rigth IDX data, on commandline with curl or in script it doesn't.

Is there a way to get the internalstate of a device like domoticz uses in the GUI,
or is there a way to do a correct json call from a linux commandline and use the data it gets?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: DzVents door.state is always open?

Post by dannybloe »

I think the eventsystem needs to be fixed.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: DzVents door.state is always open?

Post by Milifax »

dannybloe wrote:I think the eventsystem needs to be fixed.
You have more knowledge about that then I do :)

Let me know if I can help with testing or debugging.
Remember it is a strange sensor as it uses a slave for getting the right state in domoticz.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: DzVents door.state is always open?

Post by dannybloe »

Can you reproduce this with dummy switches configured as master/slave?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
cyberclwn
Posts: 103
Joined: Thursday 20 August 2015 22:53
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands
Contact:

Re: DzVents door.state is always open?

Post by cyberclwn »

Hey,

Not sure if it is the same issue, might be ... but check this post: https://www.domoticz.com/forum/viewtopi ... 96#p144096

so it might be resolved in latest beta.
3xPi 2B (Domoticz "live", Domoticz "sandbox", PhotoFrame)
RFXCom433(E), KaKu, Oregon Scientific, Keyes 2-relay, Logitech Media Server, MiLight, Smartwares heating controller(2x), IR Send/Receive, Keyes PIR, XH-M131 DuskSensor, DHT22/11
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: DzVents door.state is always open?

Post by Milifax »

cyberclwn wrote:Hey,

Not sure if it is the same issue, might be ... but check this post: https://www.domoticz.com/forum/viewtopi ... 96#p144096

so it might be resolved in latest beta.
Thanks for thinking along.
Updated to the latest beta this morning however and same issue.
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: DzVents door.state is always open?

Post by Milifax »

dannybloe wrote:Can you reproduce this with dummy switches configured as master/slave?
Missed your reply. Will try it later today. For now:

I dug into it a little deeper and came accross something I don't understand.
I've looked in the database at the values of the device which switches in Domoticz GUI to see if there is a value which switches so I can use that.
There is the nValue in the table which switches from '0' to '1', see below:

Door is open:
Image

Door is closed:
Image

However if I extract the nValue with dzvents in a script I only get a '1':

Log output, when door is closed and door is open, boith nvalues are displayed as '1'

Code: Select all

 2017-08-04 11:01:57.274 User: Admin initiated a switch command (21/Select/On)
2017-08-04 11:01:57.334 dzVents: Info: Handling events for: "Select", value: "On"
2017-08-04 11:01:57.334 dzVents: Info: ------ Start internal script: DoorCheck: Device: "Select (Select)", Index: 21
2017-08-04 11:01:57.334 dzVents: Info: Deurscript
2017-08-04 11:01:57.335 dzVents: Info: 1
2017-08-04 11:01:57.335 dzVents: Info: ------ Finished DoorCheck
2017-08-04 11:02:19.257 User: Admin initiated a switch command (21/Select/On)
2017-08-04 11:02:19.320 dzVents: Info: Handling events for: "Select", value: "On"
2017-08-04 11:02:19.320 dzVents: Info: ------ Start internal script: DoorCheck: Device: "Select (Select)", Index: 21
2017-08-04 11:02:19.320 dzVents: Info: Deurscript
2017-08-04 11:02:19.321 dzVents: Info: 1
2017-08-04 11:02:19.321 dzVents: Info: ------ Finished DoorCheck 
Script to check nValue

Code: Select all

--[[

Send a warning when the garage door has been open for more than 10 minutes

 ]]

return {
    active = true,
        on = {
             devices = {
            'Select'
            }
        },
        execute = function(domoticz, doorcontact)

                                
                domoticz.log('Deurscript')
              
                domoticz.log(domoticz.devices('Achterdeur').nValue)
               
        end
}
What is the way to get the nvalue in just Lua?
Or is there something I'm completly missing here.
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: DzVents door.state is always open?

Post by Milifax »

Ok, I can reproduce with dummies:
  • Create a dummy device name 'Dummy_BinnenDeur'
  • Create a dummy device name 'Dummy_BinnenDeur_Dicht'
  • Edit 'Dummy_Binnendeur_Dicht' and set a sub/slave device 'Dummy_BinnenDeur' for it
  • Now activate the Dummy_BinnenDeur by clicking on it. It is now on.
  • Switch it off by clicking Dummy_BinnenDeur_Dicht; Both devices will switch to off.
  • Switch On again by clicking Dummy_BinnenDeur.
As I run a script to print the nValue it now gives a '1' for every state on Dummy_BinnenDeur.

Only when I switch Dummy_BinnenDeur itself, the state of it changes to '0'.

So it has got to do with a slave that is switching the device, and then the device is not updating the nvalue.
Although it updates the value in the GUI correct.

@Dannybloe: Can you let me know if you can reproduce?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: DzVents door.state is always open?

Post by dannybloe »

I have never actually worked with this master/slave functionality but I'll give it a try.
Interesting though: so when you switch the slave (in your description) it also triggers the master. So the slave is controlling the master. That's a totally new concept of master/slave for me.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Milifax
Posts: 69
Joined: Friday 23 June 2017 9:27
Target OS: Linux
Domoticz version: 2024.4
Location: The Netherlands
Contact:

Re: DzVents door.state is always open?

Post by Milifax »

dannybloe wrote:I have never actually worked with this master/slave functionality but I'll give it a try.
Interesting though: so when you switch the slave (in your description) it also triggers the master. So the slave is controlling the master. That's a totally new concept of master/slave for me.
Yes, it does. Thought this was one of the 'features' of the master/slave :)

But what is more interesting to me, is why the nValue isn't updated correctly eventhough it is updated in the db.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: DzVents door.state is always open?

Post by dannybloe »

Ok, we have been looking at the code and it turns out that it is quite confusing:
So, let's change it a bit. Create two switches, one called Master and the other called Slave. Edit Master and add Slave there as the sub-device.
From now on, when you switch the Slave, Master follows. If you have an event script for Master and one for Slave, both scripts will be triggered and their state will be correct.
So, you start with this:
Screen Shot 2017-08-04 at 13.12.01.png
Screen Shot 2017-08-04 at 13.12.01.png (106.52 KiB) Viewed 4959 times
Screen Shot 2017-08-04 at 13.31.30.jpg
Screen Shot 2017-08-04 at 13.31.30.jpg (217.61 KiB) Viewed 4959 times

Code: Select all

return {
	on = {
		devices = {
	        'Master',
	        'Slave'
	    },
	},
	execute = function(domoticz, device)
	    print(device.name, device.state)
	end
}
Then I press Master:
Screen Shot 2017-08-04 at 13.13.42.png
Screen Shot 2017-08-04 at 13.13.42.png (51.03 KiB) Viewed 4959 times
Screen Shot 2017-08-04 at 13.14.06.png
Screen Shot 2017-08-04 at 13.14.06.png (103.13 KiB) Viewed 4959 times
And as you can see, the slave isn't affected. And only the Master script is triggered.

Now, at this stage, Master == Open and Slave == Closed.

Now, when I press the Slave:
Screen Shot 2017-08-04 at 13.16.54.png
Screen Shot 2017-08-04 at 13.16.54.png (79.84 KiB) Viewed 4959 times
This time, both Master and Slave scripts are triggered with the correct state (both Open) and when I press the Slave again:
Screen Shot 2017-08-04 at 13.18.19.png
Screen Shot 2017-08-04 at 13.18.19.png (79.97 KiB) Viewed 4959 times
Again both scripts are called now both are Closed.

But now something weird happens. When both switches are Open and you press Master in the GUI:
Screen Shot 2017-08-04 at 13.22.45.png
Screen Shot 2017-08-04 at 13.22.45.png (50.07 KiB) Viewed 4959 times
And... both Master AND Slave are Closed!! AND.. only the Master script is triggered. In the code this is commented:
//If this is a 'Main' device, and it has Sub/Slave devices,
//set the status of the Sub/Slave devices to Off, as we might be out of sync then
The problem is that when this syncing happens, the Slave-script is not triggered.

I think this describes what you see.
On top of that, the nValue isn't something you should be using in dzVents I guess as I hope all devices have more sane/readable attributes.

And, the question is: should events be triggered when you switch Master and Slave(s) are synced? I'd say yes. When a device changes, ALWAYS trigger scripts.

Anyway, I still believe that this concept of Master/Slave is counter-intuitive and very confusing. Maybe someone can explain what the intention and common use-case is for this scenario.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
jvandenbroek
Posts: 37
Joined: Wednesday 12 March 2014 16:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands
Contact:

Re: DzVents door.state is always open?

Post by jvandenbroek »

Yes, danny described it thorough. Conclusion for now: Only switch master through slaves only, not directly or via scripting. The trick in this case would probably just adding a second slave and use that for the timer.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest