Page 1 of 1

Solved--Write the value of a user variable into a dummy counter

Posted: Wednesday 21 December 2016 19:38
by Pauls
Hello,

Is there an easy way in LUA to write the value of a user variable into a dummy counter so that i can present this value in the dashboard?

Greetings,

Paul

Re: Write the value of a user variable into a dummy counter

Posted: Thursday 22 December 2016 12:48
by emme
have you tried something like
commandArray['MyCounterName'] = tostring(uservariables['MyVariableName'])

Re: Write the value of a user variable into a dummy counter

Posted: Thursday 22 December 2016 21:32
by Pauls
Hi emme,

I allready tried that without results.
commandArray['CAM02 alarm counter dummy'] = tostring(uservariables["CAM02 alarm counter"])
The variable itself (CAM02 alarm counter) is updated, but CAM02 alarm counter dummy is not upated with the value of the user variable.

However, if I remove "tostring" the following error is the result:
2016-12-22 21:16:43.614 Error: EventSystem: commandArray in script Alarm trigger CAM02 should only return ['string']='actionstring' or [integer]={['string']='actionstring'}

To be honest, i have no idea what to do with the last option [integer]={['string']='actionstring'}

Re: Write the value of a user variable into a dummy counter

Posted: Friday 23 December 2016 8:35
by emme
could you try with
commandArray[#commandArray + 1] = {['UpdateDevice'] = otherdevices_idx["CAM02 alarm counter dummy"].."|0|"..tostring(uservariables["CAM02 alarm counter"])}

if there are many updatedevice in the script you cannot use commandarray[Updatedevice], but you have to use the above syntax...
can you share your entire script and how the counter is configured? (1 value or momentary/daily?)
ciao
M

Re: Write the value of a user variable into a dummy counter

Posted: Friday 23 December 2016 19:02
by Pauls
Hi emme,

First thank you for the time you spend on my problem, it is most appriciated
Still no results with your suggestion.
It is giving an new error:
2016-12-23 18:43:59.762 Error: EventSystem: in Alarm trigger CAM02: [string "--Alarm trigger CAM 02..."]:6: attempt to concatenate field 'CAM02 alarm counter dummy' (a nil value)

What i want is quite simple.
If motion is detected, CAM02 will set a alarm (Cam achtertuin alarm) and if the alarmsystem is active (alarm_status = 2), the user variable (CAM02 alarm counter is raised by 1.
So far no problem, the user variable is indeed raised by one after motion detection.
I have made a dummy counter (CAM02 alarm counter dummy) because i want to count the number of alarm triggers (the value of the user variable) by CAM02 and present this value on my dashboard via this dummy counter.
I know that in this script the dummy counter is updated with the former value of the user variable, but that will be fix after i have this problem solved.

Code: Select all

--Alarm trigger CAM 02
commandArray = {}
if (devicechanged['Cam achtertuin alarm (On = normal)'] == "Off" and uservariables['alarm_status'] == 2 and otherdevices['CAM02 alarm overide'] == 'Off') then
    commandArray['Variable:alarm_status'] = tostring (4)
    commandArray['Variable:CAM02 alarm counter'] = tostring(uservariables["CAM02 alarm counter"] + 1)
    commandArray[#commandArray + 1] = {['UpdateDevice'] = otherdevices_idx["CAM02 alarm counter dummy"].."|0|"..tostring(uservariables["CAM02 alarm counter"])}
    commandArray['Alarm aktie dummy'] = 'On FOR 3'
    commandArray['Tuin Verlichting'] = 'On FOR 2'
    commandArray['CAM02 alarm overide'] = 'On FOR 2.2'
    commandArray['SendNotification']='Domoticz#alarm systeem meld beweging detectie CAM 02#0'
    print ('### Alarm status = 4, alarm trigger CAM 02')
end
return commandArray

Re: Write the value of a user variable into a dummy counter

Posted: Wednesday 28 December 2016 10:10
by Pauls
I found a contribution from mvzut for a playstion uptime counter.
That helped me to get this working.
So, if you have a global variable and you want to have this value presented on your dashboard, you follow these steps.

First make a dummy with as sensor type "custom sensor" and note the IDX for this sensor (175 in the example).
This sensor will be used to present the value of the global variable on the floorplan or just the dashboard, in the example "testvar" .
save the script as a time based script.

Code: Select all

commandArray = {}
local localvar1 = 175
    commandArray['UpdateDevice'] = localvar1 .. '|0|' .. tostring(uservariables["testvar"])
return commandArray

Re: Solved--Write the value of a user variable into a dummy counter

Posted: Thursday 12 January 2017 15:44
by gurushastri
Hi,
thanks. this helped me a bit. but a question - is there a way to count all the time something was on during a 24 hrs period maybe?
every time you turn something on and off it counts the differential. but the next activation it will just go to zero again..can i keep the old number somehow and add the new activation to it?