Page 1 of 2
Trigger on "Dummy/Usage/Electric" device
Posted: Friday 11 August 2017 11:48
by Freemann
I have a Dummy device which holds the "household power usage", which can be positive or negative (solar panels production) value.
I want to trigger on this device, but I can't get it to work.
Here's the script;
Code: Select all
return {
active = true,
on = {devices = {'WebSolarLog - HuisVerbruik'}},
execute = function(domoticz, device)
domoticz.notify('Energy trigger!!')
domoticz.email('Energy trigger!!')
end
}
'WebSolarLog - HuisVerbruik' is the dummy device.
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Tuesday 15 August 2017 8:08
by Freemann
Nobody an solution?
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Tuesday 15 August 2017 8:15
by freijn
This one is in Lua , not perfect (as I am struggeling with the trigger as well )but working.
My problem is that the updates from the solar are much less then the power meter , hence you get weird values now and then.
I still need to work on report after the solars are not generating energy anymore.
Perhaps it helps you getting started ?
Code: Select all
--
-- Domoticz passes information to scripts through a number of global tables
--
-- device changed contains state and svalues for the device that changed.
-- devicechanged['yourdevicename'] = state
-- devicechanged['svalues'] = svalues string
--
commandArray = {}
--powersensor = "Power"
--if (devicechanged[powersensor]) then
-- print( " ####Power debug: "..devicechanged[powersensor])
-- commandArray['Variable:LUX']=tostring(devicechanged[luxsensor])
-- var1, var2,var3,var4,var5,var6 = string.match(otherdevices_svalues['Power'], "(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*)")
-- print( " ####Power debug: "..var6)
-- end
solarsensor = "SolarEdge kWh"
if (devicechanged[solarsensor]) then
--print( " ####Solar debug: "..devicechanged[solarsensor])
Solarvar1, var2 = string.match(otherdevices_svalues[solarsensor], "(%d+%.*%d*);(%d+%.*%d*)")
print( " ####Solar debug: "..Solarvar1)
powersensor = "Power"
-- if (devicechanged[powersensor]) then
--print( " ####Power debug: "..devicechanged[powersensor])
var1, var2,var3,var4,Powervar5,Powervar6 = string.match(otherdevices_svalues['Power'], "(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*);(%d+%.*%d*)")
print( " ####Power debug: "..Powervar5)
powercount = tonumber(Powervar6)
solarcount = tonumber(Solarvar1)
consume = solarcount - powercount
print( " ####Consume debug: "..consume)
ttidx = otherdevices_idx['PowerConsumtion']
commandArray['UpdateDevice'] = ttidx..'|0|'..consume
end
return commandArray
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Tuesday 15 August 2017 8:22
by Freemann
Thanks for your script and code!
I also have a very extensive LUA scripts to do certain stuff based on my Solar production.
I'm moving some native LUA scripts to dzVents and now I'm struggling to get the script triggered on the Dummy Energy device.
So for now my native LUA is running OK, but I can't get it to work in dzVents.
Really want to get this to work, because dzVents is an awesome extension and save me a lot of coding

Re: Trigger on "Dummy/Usage/Electric" device
Posted: Tuesday 15 August 2017 8:36
by dannybloe
Ok, there are a couple of things you can try. First of all, you can put dzVents in debug logging mode (Domoticz settings). Then see in the log if you can see if there is an event triggered if your device was changed. dzVents should log this even though it may not call your script. Also, maybe trivial, make sure the script is active if you created it using the web editor to create the script. I tend to forget this occasionally myself.
If that is all the case, try to use the id/idx instead of the device name to create the on-trigger and see if that works.
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Wednesday 16 August 2017 20:59
by Freemann
Logging isn't showing an trigger (debug is at highest level), also the notify and email are not received.
Will try the IDX option and report back.
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Wednesday 16 August 2017 21:19
by Freemann
script is now, with IDX in place, looking like this;
Code: Select all
return {
active = true,
on = {devices = {82153}},
execute = function(domoticz, device)
domoticz.email('Energy trigger!!')
domoticz.notify('Energy trigger!!')
end
}
No notifications and/or email and here's the logscreen and device with its last trigger time;

- Screenshot - 16_08_2017 , 21_15_48.png (103.04 KiB) Viewed 4613 times
(the red oval should be one device lower)
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Wednesday 16 August 2017 23:08
by dannybloe
Is that the id of the device??? Check the idx column of the device list in domoticz. Never seen such a high number.
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Thursday 17 August 2017 8:25
by mivo
Hi,
some time ago I had a problem with virtual Temperature device - LUA (nor dzVents ?) not triggered on device change. I solved it differently, but now i tested it again - looks it still not works (on beta 3.8312 currently). Maybe other dummy/virtuals types have same problem.
Simple script:
Code: Select all
return {
active = true,
on = {
devices = {
'esp Temp' -- virtual Temperature device
}
},
execute = function(domoticz, esp)
domoticz.log('esp Temp changed')
end
}
Then update via JSON call:
Code: Select all
192.168.1.23:8080/json.htm?type=command¶m=udevice&idx=126&nvalue=0&svalue=21
Script not triggered. Interesting part - simple Blockly event works OK

- Blockly
- IMG_0212.JPG (155.61 KiB) Viewed 4578 times
Code: Select all
2017-08-17 08:17:01.434 Blockly: esp Temp
Is it bug or feature ?

(I think it's in Domoticz event system, not dzVents)
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Thursday 17 August 2017 9:35
by dannybloe
mivo wrote: ↑Thursday 17 August 2017 8:25
Hi,
some time ago I had a problem with virtual Temperature device - LUA (nor dzVents ?) not triggered on device change. I solved it differently, but now i tested it again - looks it still not works (on beta 3.8312 currently). Maybe other dummy/virtuals types have same problem.
Simple script:
Code: Select all
return {
active = true,
on = {
devices = {
'esp Temp' -- virtual Temperature device
}
},
execute = function(domoticz, esp)
domoticz.log('esp Temp changed')
end
}
Then update via JSON call:
Code: Select all
192.168.1.23:8080/json.htm?type=command¶m=udevice&idx=126&nvalue=0&svalue=21
And you are sure that the script is active in the internal editor and dzVents is enabled? Does it log anything when dzVents is set to debug logging after you call the json?
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Thursday 17 August 2017 10:19
by mivo
Aah, sorry Danny, I had dzVents logging set to
Errors + forced - too early morning

. Works now via JSON call for dummy Temperature and dummy Usage/Electric too.
I just looked to my old scripts, where I tested behaviour of not triggering Dummy Temp device. It worked via JSON call, but not by domoticz.devices('some dev').updateTemperature(). Tested now again and I can confirm it.
@Freemann, how do you update dummy Usage/Electric device, which does not trigger script ? JSON, or LUA/dzVents method ?
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Thursday 17 August 2017 11:07
by Freemann
Tried to duplicate the dzVents script to Blocky and it looks like Blocky is also not triggering on the changes of the Dummy device.
I update the dummy devices through LUA and here's and short snippet;
Code: Select all
dIDX = getDeviceIDX('WebSolarLog - ZonneStroom')
commandArray[1] = {['UpdateDevice'] = dIDX .. '|0|' .. data.totals.production.GPOverall}
dIDX = getDeviceIDX('WebSolarLog - HuisVerbruik')
commandArray[2] = {['UpdateDevice'] = dIDX .. '|0|' .. data.totals.metering.liveEnergy}
dIDX = getDeviceIDX('WebSolarLog - StroomBeschikbaar')
commandArray[3] = {['UpdateDevice'] = dIDX .. '|0|' .. powerAvailable}
I'm now a bit lost on this subject.
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Thursday 17 August 2017 11:22
by dannybloe
Ok, back to the start.. you have a device 'WebSolarLog - HuisVerbruik' and you want it to be triggered by dzVents but that doesn't happen somehow.
In my dzVents development branch I have added a troubleshooting section to the documentation. This is not in the wiki yet but perhaps you can read it and see if that helps you (most of the stuff in the troubleshooting section should still work in the current released version):
Troubleshooting
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Thursday 17 August 2017 11:44
by Freemann
Nice Wiki!
Is dzVents enabled?
Yes
Is your script enabled?
Yes
Turn on debug logging;
is at highest level
/path/to/domoticz/scripts/dzVents/domoticzData.lua with open this file in an editor and see if you can find your device/variable/scene/group in there.
Yes its there (see code snippet)
Code: Select all
[20] = {
["switchTypeValue"] = 0;
["name"] = "WebSolarLog - HuisVerbruik";
["id"] = 153;
["data"] = {
["hardwareName"] = "Dummy";
["hardwareType"] = "Dummy (Does nothing, use for virtual switches only)";
["_nValue"] = 0;
["hardwareTypeValue"] = 15;
["protected"] = false;
["_state"] = "-440";
["icon"] = "current";
["unit"] = 1;
["hardwareID"] = 5;
};
["lastLevel"] = 0;
["timedOut"] = false;
["batteryLevel"] = 255;
["deviceID"] = "82153";
["switchType"] = "On/Off";
["rawData"] = {
[1] = "-440";
};
["baseType"] = "device";
["deviceType"] = "Usage";
["description"] = "";
["signalLevel"] = 12;
["lastUpdate"] = "2017-08-17 11:28:01";
["subType"] = "Electric";
["changed"] = false;
};
So, every time Domoticz starts dzVents ánd debug logging is enabled you should see these lines:
dzVents version: x.y.z
Event trigger type: xxxx
Yes I See (see code snippet)
Code: Select all
2017-08-17 11:40:45.930 dzVents: Debug: Device-adapter found for Warmtepomp(kWh): kWh device adapter
2017-08-17 11:40:45.941 dzVents: Debug: Processing device-adapter for Warmtepomp(kWh): kWh device adapter
2017-08-17 11:40:45.941 dzVents: Debug: Device-event for: Warmtepomp(kWh) value: 0.000;147980.000
2017-08-17 11:40:45.941 dzVents: Debug: Searching for scripts for changed item: Warmtepomp(kWh)
Script is still not execued?
If for some reason you script is not executed while all of the above is done, it is possible that your triggers are not correct.
There's no timerule and the ID's are (now) correct (153)
Also, make sure that your device names are unique!
Name is unique
If your script is still not triggered, you can try to create a classic Lua event script and see if that does work.
Tried to make a classic LUA and that's also not working (already posted that)
Debugging your script
The script is very straight forward.... what should i debug?
Get help
The Domoticz forum is a great resource for help and solutions. Check the dzVents forum.
HELP!
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Friday 18 August 2017 9:00
by dannybloe
Freemann wrote: ↑Thursday 17 August 2017 11:44
So, every time Domoticz starts dzVents ánd debug logging is enabled you should see these lines:
dzVents version: x.y.z
Event trigger type: xxxx
Yes I See (see code snippet)
Code: Select all
2017-08-17 11:40:45.930 dzVents: Debug: Device-adapter found for Warmtepomp(kWh): kWh device adapter
2017-08-17 11:40:45.941 dzVents: Debug: Processing device-adapter for Warmtepomp(kWh): kWh device adapter
2017-08-17 11:40:45.941 dzVents: Debug: Device-event for: Warmtepomp(kWh) value: 0.000;147980.000
2017-08-17 11:40:45.941 dzVents: Debug: Searching for scripts for changed item: Warmtepomp(kWh)
This confuses me. In your Domoticz version you should see something like this every time dzVents starts processing:
Event trigger type: ... I don't see that here. And... Warmtepomp? I was expecting to see 'WebSolarLog - HuisVerbruik'.
What did you do exactly to trigger this event (if it would work)?
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Friday 18 August 2017 9:27
by Freemann
This was just a random set of lines, because I don't see the 'WebSolarLog - HuisVerbruik' coming by.
This is the current script;
Code: Select all
return {
active = true,
on = {devices = {153,'153','WebSolarLog - HuisVerbruik'}},
execute = function(domoticz, device)
domoticz.email('Energy trigger!!')
domoticz.notify('Energy trigger!!')
end
}
Made a test script triggering on a motion sensor in the dining and this is the Log result on trigger;
Code: Select all
2017-08-18 09:30:55.181 dzVents: Debug: Device-adapter found for Eettafel Eye(Motion): Switch device adapter
2017-08-18 09:30:55.185 dzVents: Debug: Processing device-adapter for Eettafel Eye(Motion): Switch device adapter
2017-08-18 09:30:55.186 dzVents: Debug: Device-event for: Eettafel Eye(Motion) value: On
2017-08-18 09:30:55.186 dzVents: Debug: Searching for scripts for changed item: Eettafel Eye(Motion)
2017-08-18 09:30:55.186 dzVents: Info: Handling events for: "Eettafel Eye(Motion)", value: "On"
2017-08-18 09:30:55.186 dzVents: Info: ------ Start internal script: ForumTest: Device: "Eettafel Eye(Motion) (Zwave)", Index: 763
2017-08-18 09:30:55.186 dzVents: Info: ------ Finished ForumTest
2017-08-18 09:30:55.186 dzVents: Debug: [1] = SendNotification: Light info#The light Eettafel Eye(Motion) will be switched off soon#0#pushover##
2017-08-18 09:30:55.186 dzVents: Debug: =====================================================
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Friday 18 August 2017 11:12
by dannybloe
Ok, but I'm more interesting in what you do that should cause the 'WebSolarLog - HuisVerbruik' script to be executed.
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Friday 18 August 2017 12:25
by mivo
Hi,
JSON / openUrl update method of dummy device triggers script correctly:
This script updates dummy device based on switch states (just example):
test_switch.lua
Code: Select all
return {
active = true,
logging = {
level = domoticz.LOG_INFO,
},
on = {
-- trigger on device with name
devices = {'switch'}
},
execute = function(domoticz, device)
-- check state of device
if device.state == 'On' then
-- log for debugging purpose
domoticz.log('switch is ON')
-- JSON call
local updDevice = domoticz.devices('test temp') -- device to update
local newValue = '21' -- new value
url = domoticz.settings['Domoticz url'] ..
'/json.htm?type=command¶m=udevice&idx=' .. updDevice.idx .. '&nvalue=0&svalue=' .. newValue
domoticz.log('Setting temp using openURL ' .. url)
domoticz.openURL(url)
elseif device.state == 'Off' then
-- log for debugging purpose
domoticz.log('switch is OFF')
-- JSON call
local updDevice = domoticz.devices('test temp') -- device to update
local newValue = '23' -- new value
url = domoticz.settings['Domoticz url'] ..
'/json.htm?type=command¶m=udevice&idx=' .. updDevice.idx .. '&nvalue=0&svalue=' .. newValue
domoticz.log('Setting temp using openURL ' .. url)
domoticz.openURL(url)
end
end
}
Temp dummy/virtual device script:
test_temp.lua
Code: Select all
return {
active = true,
logging = {
level = domoticz.LOG_INFO,
},
on = {
-- trigger on device with name
devices = {'test temp'}
},
execute = function(domoticz, device)
domoticz.log('test temp CHANGED')
end
}
Results in log:
Code: Select all
2017-08-18 12:20:02.468 User: Admin initiated a switch command (4/switch/On)
2017-08-18 12:20:02.469 (virtual) Light/Switch (switch)
2017-08-18 12:20:02.489 dzVents: Info: Handling events for: "switch", value: "On"
2017-08-18 12:20:02.489 dzVents: Info: ------ Start external script: test_switch.lua: Device: "switch (virtual)", Index: 4
2017-08-18 12:20:02.489 dzVents: Info: switch is ON
2017-08-18 12:20:02.489 dzVents: Info: Setting temp using openURL http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=16&nvalue=0&svalue=21
2017-08-18 12:20:02.489 dzVents: Info: ------ Finished test_switch.lua
2017-08-18 12:20:02.489 EventSystem: Fetching url...
2017-08-18 12:20:02.489 EventSystem: Script event triggered: /opt/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-08-18 12:20:02.733 dzVents: Info: Handling events for: "test temp", value: "21"
2017-08-18 12:20:02.733 dzVents: Info: ------ Start external script: test_temp.lua: Device: "test temp (virtual)", Index: 16
2017-08-18 12:20:02.733 dzVents: Info: test temp CHANGED
2017-08-18 12:20:02.733 dzVents: Info: ------ Finished test_temp.lua
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Friday 18 August 2017 14:54
by dannybloe
Yes, I see this.. we are exploring this and see if we can fix this. Thing is that perhaps people in some situation don't expect the event system to be triggered when sending in UpdateDevice command.
Re: Trigger on "Dummy/Usage/Electric" device
Posted: Friday 18 August 2017 16:56
by Freemann
What do you need from me to help debug this further?