dzVent version info and .isDevice not working  [Solved]

Easy to use, 100% Lua-based event scripting framework.
Post Reply
rogzon
Posts: 11
Joined: Monday 14 November 2016 10:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

dzVent version info and .isDevice not working

Post by rogzon » Thursday 21 June 2018 14:21

Hi!
I have searched thru the whole Internet for an answer on how to get the version number of my installed dzVents.....
Is there somewhere version information for dzVents?
Also I have this:

Code: Select all

return {
	active = true, -- set to false to disable this script
	on = {
		devices = {
			224, -- id
		},
		httpResponses = { 
		    'scheduleinfo', 
		}
	},

	execute = function(domoticz, device)
	    if (device.isDevice) then
	         print('Device!')
		end
	end
}
I have taken away the http stuff for now but, what I can understand is that if I push the switch(224) the device.isDevice should return true?
It doesn't, when trying "print(device.isDevice)" i get " ... isDevice is a nil value" in my log.
Is this because a dzVent version problem?

/
Last edited by dannybloe on Thursday 21 June 2018 16:01, edited 1 time in total.
Reason: Use code tags please

snellejellep
Posts: 105
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi
Domoticz version: 3.97xx
Location: The Neterlands
Contact:

Re: dzVent version info and .isDevice not working  [Solved]

Post by snellejellep » Thursday 21 June 2018 14:28

to get your version number for dzvents you can go to <your domoticz url>/#/About
raspberry pi | xiaomi gateway/vacuum | yeelight | philips hue | zwave |ubiquiti unifi | harmony

rogzon
Posts: 11
Joined: Monday 14 November 2016 10:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: dzVent version info and .isDevice not working

Post by rogzon » Monday 25 June 2018 22:09

For anybody else reading this..
The version info is available in the About dialog but for some reason I needed to update to 4.9700 to even have an entry stating the dzVents version...
Also device.isDevice is working now.
The only thing completely missing now is device.isSchedule which should return true if the switch would be toggled by a schedule.
It would be quite handy...

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

Re: dzVent version info and .isDevice not working

Post by waaren » Monday 25 June 2018 23:06

rogzon wrote:
Monday 25 June 2018 22:09
The only thing completely missing now is device.isSchedule which should return true if the switch would be toggled by a schedule.
It would be quite handy...
If you want to have information if a device state is triggered by a schedule you could use the information in the domoticz log to identify this.

Code: Select all

-- isScheduled.lua  

triggerDevice = 985  -- define the switch you want to monitor

return {
    on      =   {   httpResponses   =   { "get_DomoticzLogLines" },
                    devices         =   { triggerDevice}},
                    
    logging =   {   level     =   domoticz.LOG_INFO,
                    marker    =   "get triggered by info from log"    },

    execute = function(dz, trigger)
        
        local function askDomoticzForLogLines()
            local lastLogTime = os.time(os.date('*t')) - 10    -- current Time as seconds from epoch  - 10 should get enough logging
            local logLevel    = 2                              -- loglevel (1=normal,2=Status,4=error,268435455=all
            local jsonString  = "/json.htm?type=command&param=getlog&" ..
                                "lastlogtime=" .. tostring(lastLogTime) ..
                                "&loglevel=" .. logLevel
   
            dz.openURL  ({ url      = dz.settings["Domoticz url"] .. jsonString,   -- loglevel 2 ==>> Status:logURL,
                           method   = "GET", callback = "get_DomoticzLogLines" })
        end
        
        -- Get information recent log entries for switch action
        function isScheduled(device)
           local resultTable = trigger.json.result
           for i = #resultTable,1,-1 do                  -- Read backwards to get latest switchoperation first
                if      string.find(resultTable[i].message,device.name) and                             -- Look for Device name , update Time 
                        string.find(resultTable[i].message,device.lastUpdate.rawTime) and               -- and string Schedule...
                        string.find(resultTable[i].message,"Schedule") and               -- and strings User: and initiated...
                        not(string.find(resultTable[i].message,"dzVents")) then
                        return true
                end
            end
            return false
        end                                             
        
        if trigger.isDevice then
            askDomoticzForLogLines()
        else     
            if isScheduled(dz.devices(triggerDevice)) then
                dz.log(dz.devices(triggerDevice).name .. " IS triggered by schedule",dz.LOG_INFO)
            else
                dz.log(dz.devices(triggerDevice).name .. " NOT triggered by schedule",dz.LOG_INFO)
            end    
       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

rogzon
Posts: 11
Joined: Monday 14 November 2016 10:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: dzVent version info and .isDevice not working

Post by rogzon » Wednesday 27 June 2018 11:52

Yes, that's a good idea. For now I am storing on and off time as string in a variable like this:

Code: Select all

return {
	active = true, -- set to false to disable this script
	on = {
		devices = {
			224, -- id
		},
		httpResponses = { 
		    'scheduleinfo', 
		}
	},

	execute = function(domoticz, device)
	    if (device.isDevice) then
            print('Device!')
	        if(device.state == 'On') then
                domoticz.openURL({
                    url = 'http://192.001.01.02:8080/json.htm?type=schedules',
                    method = 'GET',
                    callback = 'scheduleinfo'})
		    end
		end
		if (device.isHTTPResponse and device.ok) then
		    print('HTTPResponse!')
		    local results = device.json.result
		    for i, node in pairs(results) do
		        if(node.DeviceRowID == 3) then
		            print(node.DevName .. ' ' .. node.Active .. ' ' .. node.Time .. ' ' .. node.TimerCmd)
		            if (node.TimerCmd==1) then
		                domoticz.variables('mvhScheduleOffTime').set(node.Time)
		            else
		                domoticz.variables('mvhScheduleOnTime').set(node.Time)
	                end
		        end
	        end
	    end
	end
}
I did however succeed in my original quest which was distinguishing between a physical button push and "on by schedule" in a device event.
I simply moved the timer to a group and put my switch into that group. By setting a uservariable in the "schedule on" event I now know that it wasn't a physical button push.
This comes in handy when controlling engine heaters during winter, push the button means on for 3 hours but don't turn off if schedule has kicked in..

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest