Page 1 of 1

Write a value from Dimmer to Percent Display

Posted: Wednesday 28 February 2018 7:45
by Stanislaw
Good morning,

I need a little help with a simple exercise. I would like to rewrite a value from a virtual dimmer to a percentage display. How I'm trying to do that:

Code: Select all

local iDimmer = tonumber (otherdevices['Dimmer']) --Input

local qDimmer = 'Percent' --Output


commandArray = {}


--I'v tried:

qDimmer = iDimmer

--And like that

commandArray[qDimmer] = tonumber(iDimmer) 

return commandArray

I created a virtual sensor "Percentage" named "Percent" but it doesn't work.

I'm learning LUA, I understand how to read a value from devices but I don't know how to write values for example to a virtual indicators :/

Is there any tutorial about that? I'm trying to google that but without luck...

Re: Write a value from Dimmer to Percent Display

Posted: Wednesday 28 February 2018 10:16
by freijn
I do not have an answer for you but my plan of attack would be :

make a print statement in your script like :

with the Debug you can then turn it on and off easy :-)

Code: Select all

local Debug

Debug = "YES"                    -- Turn debugging on ("YES") or off ("NO")
 
----------------------------------------------------------------------------------------------------------
-- header text
----------------------------------------------------------------------------------------------------------
some code here  bla bla bal



if Debug=="YES" then
    print( "My text to write in debug file  debug: ")
    print(">>qDimmer =   " ..qDimmer)
end 

Re: Write a value from Dimmer to Percent Display

Posted: Wednesday 28 February 2018 13:45
by Stanislaw
freijn thanks for help but I'm watching values of variables by using prDebug:

Code: Select all

function prDebug(sString)
  if(bDebug) then
   print ( sString )
  end
end
Still can't solve the problem....So many hours lost :(

Re: Write a value from Dimmer to Percent Display

Posted: Wednesday 28 February 2018 14:41
by waaren
dzVents hides most of the complexity of using LUA in combination with domoticz for you and therefore is much easier to learn. This is especial true when starting with programming in this area.

Happy to help if you still have questions after looking at

http://www.domoticz.com/forum/viewtopic ... 59&t=18143

and

http://www.domoticz.com/forum/viewtopic ... 59&t=18674

Re: Write a value from Dimmer to Percent Display

Posted: Thursday 01 March 2018 8:54
by Stanislaw
waaren wrote: Wednesday 28 February 2018 14:41 dzVents hides most of the complexity of using LUA in combination with domoticz for you and therefore is much easier to learn. This is especial true when starting with programming in this area.

Happy to help if you still have questions after looking at

http://www.domoticz.com/forum/viewtopic ... 59&t=18143

and

http://www.domoticz.com/forum/viewtopic ... 59&t=18674
Thanks waaren, dzVents looks great and I will learn it for sure. Really good stuff :)

But for now, i will focus on LUA because I'v got some good code this type that I want to use.

With a simple code like below, I am able to write a value from code to outside variable. Take a look on that masterpiece ;)

Code: Select all

commandArray = {}

print ("All based event fired");

internal_var1 = 5 + 10

print(internal_var1)

commandArray['Variable:outside_var1'] = tostring(internal_var1)
print(internal_var1)

return commandArray
Przechwytywanie.JPG
Przechwytywanie.JPG (32.29 KiB) Viewed 1294 times
So now I'm wondering how can I display this variable? What kind of indicator should I use?

----------------------------------------

Then next step is to rewrite a value from a dimmer to this outside variable and then visualize it for example in Percentage indicator.

I tried like this but it doesn't work:

Code: Select all

local i_dimmer = otherdevices['Dimmer']

commandArray = {}

print ("All based event fired");

local internal_var1 = i_dimmer

commandArray['Variable:outside_var1'] = tonumber(internal_var1)
print(internal_var1)

return commandArray
Any suggestions? :)

Re: Write a value from Dimmer to Percent Display

Posted: Thursday 01 March 2018 20:40
by Stanislaw
Sorry that I'm asking for a such basic things but I'm not a software developer, just trying to have some fun :)

Can somebody tell me just last more thing? If I'm using command:

Code: Select all

commandArray['UpdateDevice'] = '13|0|30'
To write something to a Percentage Display, can I put somehow a value from another variable instead a constatnt "30"?

for example:

Code: Select all

var1 = 55

commandArray['UpdateDevice'] = '13|0|var1'
That code above doesn't work - is there some other way?


---------------EDIT:

OK It's working :)

Code: Select all

local i_dimmer = otherdevices_svalues['Dimmer']

commandArray = {}

local internal_var1 = i_dimmer

commandArray['UpdateDevice'] = '13|0|'..internal_var1 

return commandArray
By that we can write a value from dimmer to indicator (for example Custom Sensor)

Thanks for help :)