Write a value from Dimmer to Percent Display

Moderator: leecollings

Post Reply
Stanislaw
Posts: 5
Joined: Wednesday 28 February 2018 7:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Write a value from Dimmer to Percent Display

Post 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...
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Write a value from Dimmer to Percent Display

Post 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 
Stanislaw
Posts: 5
Joined: Wednesday 28 February 2018 7:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Write a value from Dimmer to Percent Display

Post 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 :(
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Write a value from Dimmer to Percent Display

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Stanislaw
Posts: 5
Joined: Wednesday 28 February 2018 7:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Write a value from Dimmer to Percent Display

Post 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 1289 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? :)
Stanislaw
Posts: 5
Joined: Wednesday 28 February 2018 7:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Write a value from Dimmer to Percent Display

Post 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 :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest