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
Solved--Write the value of a user variable into a dummy counter
Moderator: leecollings
-
- Posts: 28
- Joined: Sunday 19 June 2016 9:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Solved--Write the value of a user variable into a dummy counter
Last edited by Pauls on Wednesday 28 December 2016 10:11, edited 1 time in total.
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Write the value of a user variable into a dummy counter
have you tried something like
commandArray['MyCounterName'] = tostring(uservariables['MyVariableName'])
commandArray['MyCounterName'] = tostring(uservariables['MyVariableName'])
The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
-
- Posts: 28
- Joined: Sunday 19 June 2016 9:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Write the value of a user variable into a dummy counter
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'}
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'}
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Write the value of a user variable into a dummy counter
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
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
The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
-
- Posts: 28
- Joined: Sunday 19 June 2016 9:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Write the value of a user variable into a dummy counter
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.
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
-
- Posts: 28
- Joined: Sunday 19 June 2016 9:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Write the value of a user variable into a dummy counter
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.
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
-
- Posts: 7
- Joined: Monday 26 December 2016 18:59
- Target OS: Windows
- Domoticz version:
- Contact:
Re: Solved--Write the value of a user variable into a dummy counter
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?
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?
Who is online
Users browsing this forum: No registered users and 0 guests