dzvents alertsensor log entry

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

Moderator: leecollings

Post Reply
wayfinder
Posts: 4
Joined: Friday 06 September 2019 1:40
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11005
Contact:

dzvents alertsensor log entry

Post by wayfinder »

I have a script (below) that updates a Dummy Alert sensor Set up as Type: General SubType: Alert

When I use json from a browser to update sensor updates and there is an entry in the sensor log
Http://192.xxx.xxx.xxx:8080/json.htm?ty ... =%27RED%27

In Dzvents using update AlertSensor sensor updates but there is no entry in the sensor log
dz.devices(118).updateAlertSensor(ALERTLEVEL_YELLOW, 'Moderate')

Is there something else I need to do in Dzvents?


Thanks

-Gary
Spoiler: show

Code: Select all

return {
	on = {
		timer = {
			'every 30 minutes', 
			--'every minute',
		},
		httpResponses = {
			'all', 
		},
		devices = {
        'HRV Recirc SW', 
    },
	},

    logging = {
            level = domoticz.LOG_ERROR,
            marker = "AQI Alert"
       },
       
	execute = function(dz, item)
	    
	    if (item.isTimer) then
			dz.openURL({
				url = 'http://192.168.1.29:8080/json.htm?type=devices&rid=111',
				method = 'GET',
				callback = 'all', -- see httpResponses above.
				--dz.log('Timer OpenURL')
			})
			
			elseif (item.isDevice) then 
        
           -- dzlog(HRV.state)
           
                --if (item.active) then
                if (dz.devices(150).active) then
                dz.devices(118).updateAlertSensor(ALERTLEVEL_YELLOW, 'Moderate')
                dz.devices(147).switchOn()
                
            else
                dz.devices(147).switchOff()
                
                dz.devices(118).updateAlertSensor(ALERTLEVEL_GREEN, 'GOOD')
             end
		

		elseif (item.isHTTPResponse) then
--dz.log('HTTPResponse')
			if (item.statusCode == 200) then
			   -- dz.log('Status 200')
				if (item.isJSON) then
				     PM2_5 = item.json.result[1]['Data']; 
                   --dz.log('RAW '.. PM2_5 )
                    PM2_5Value = string.sub(PM2_5, 1, 1)
                  --dz.log('ug/m3  ' .. PM2_5Value )
                    AlertLevel = tonumber(PM2_5Value)
                   dz.log('AlertLevel  ' .. AlertLevel )
                   
                                   --PM2.5 ug/m3   AirQI
                    if ((AlertLevel) <=12 ) then
                                dz.devices(118).updateAlertSensor(ALERTLEVEL_GREEN, 'GOOD')
                                --dz.devices(147).switchOff().checkFirst()        -- switch HRV into fresh air mode
                             
                                if (dz.devices(150).active) then
                            dz.devices(147).switchOn()
                                else
                                dz.devices(147).switchOff().checkFirst()        -- switch HRV into fresh air mode
                                end
                                
                    --0.0-12          0-50    Green/Good  1
                    
                    elseif ((AlertLevel) >=13 and (AlertLevel)<=35 ) then
                                dz.devices(118).updateAlertSensor(ALERTLEVEL_YELLOW, 'Moderate')
                                dz.devices(147).switchOn()                  --switch HRV into recirculation
                    --12.1-35.4       51-100  Moderate/yellow  2
                    
                    elseif ((AlertLevel) >=36 and (AlertLevel)<=55 ) then
                                dz.devices(118).updateAlertSensor(ALERTLEVEL_ORANGE, 'Unhealthy sensitive Groups')
                                 dz.devices(147).switchOn()
                    --35.5-55.4       101-150 Orange/Unhealthy sensitive Groups  3
                    elseif ((AlertLevel) >=56 and (AlertLevel)<=150 ) then
                                dz.devices(118).updateAlertSensor(ALERTLEVEL_RED, 'UNHEALTHY')
                                 dz.devices(147).switchOn()
                    --55.5-150.4      151-200 RED/UNHEALTHY 4
                end
      
                    end
                  
                      
				
			end
			else
				dz.log('There was a problem handling the request', dz.LOG_ERROR)
				dz.log(item, dz.LOG_ERROR)
			end

		end

}

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

Re: dzvents alertsensor log entry

Post by waaren »

wayfinder wrote: Friday 06 September 2019 2:02 dz.devices(118).updateAlertSensor(ALERTLEVEL_YELLOW, 'Moderate')
The constansts ALERTLEVEL_<COLOR> only exist within the domoticz object. So in your code you should refer to them using.
dz.ALERTLEVEL_YELLOW, dz.ALERTLEVEL_GREEN, dz.ALERTLEVEL_ORANGE and dz.ALERTLEVEL_RED
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
wayfinder
Posts: 4
Joined: Friday 06 September 2019 1:40
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11005
Contact:

Re: dzvents alertsensor log entry

Post by wayfinder »

Thank you Waaren!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest