LUA dimmer resend last setpoint

Moderator: leecollings

Post Reply
stedew
Posts: 3
Joined: Tuesday 24 November 2015 8:19
Target OS: Windows
Domoticz version:
Contact:

LUA dimmer resend last setpoint

Post by stedew »

Hello Experts,

I am toy-ing with a ESP8266 and want to set the PWM functionality from Domoticz.
After a few hours (ahum) i scratched this lua script together:

Code: Select all

  
local Url_espdimmer ='192.168.0.107'



commandArray = {}

if (devicechanged['Virtual2']~=nil) then --Test for checking only this device
	--The ESP have a range from 0 to 1024 so multiply with 10.24
	print(" ==> Virtual2 " .. tostring(devicechanged['Virtual2']) .. " state )")

	
	local dvalue = tonumber(otherdevices_svalues['Virtual2'])
	dvalue = dvalue * 10.24
	
	print(" ==> to change for dimmer " .. tostring(dvalue) .. " new value )")
  	commandArray['OpenURL']='http://' .. Url_espdimmer.. '/control?cmd=PWM,2,' .. tostring(dvalue) .. ' '
end


return commandArray 
Works nice (saved in ~/pi/Domoticz/lua/script_device_Virtual2.lua)
Every time i set a new level with Virtual2 the PWM is updated....
Only when i switch on (no Set Level) the level value = 0 while in the GUI there is still 30% for example.
So how can i get the previous level (in the web interface the level stay's visible).
Can it be done without creating uservariables ?
Tnx in advance,
Stefan.
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: LUA dimmer resend last setpoint

Post by simonrg »

stedew wrote:Hello Experts,
I am toy-ing with a ESP8266 and want to set the PWM functionality from Domoticz.
After a few hours (ahum) i scratched this lua script together:
..........
Works nice (saved in ~/pi/Domoticz/lua/script_device_Virtual2.lua)
Every time i set a new level with Virtual2 the PWM is updated....
Only when i switch on (no Set Level) the level value = 0 while in the GUI there is still 30% for example.
So how can i get the previous level (in the web interface the level stay's visible).
Can it be done without creating uservariables ?
Tnx in advance,
Stefan.
Stefan,

Your logic seems fine and I would have thought that if the light is switch off, then the dim level could be 0, but when it switches on then dim level should not be 0, so there would appear to be a bug with svalue no longer reflecting dim value after light is switch off / on without dim level change.

You could retrieve status via json, which is effectively what the GUI does and here the dim level is correctly stored in both Level and LevelInt.
http://192.168.8.1:8080/json.htm?type=devices&rid=idx. Using json would avoid the use of a uservariable, but you would need to work out how to retrieve and process the json.

What is PWM? Which design of ESP8266 dimmer have you made?

Best wishes, Simon

Code: Select all

-- script_device_Virtual2.lua
local Url_espdimmer ='192.168.0.107'
commandArray = {}

if devicechanged['Virtual2'] then --Test for checking only this device
	--The ESP have a range from 0 to 1024 so multiply with 10.24
	print(" ==> Virtual2 " .. tostring(devicechanged['Virtual2']) .. " state )")
	local dvalue = tonumber(otherdevices_svalues['Virtual2'])
	dvalue = math.floor(dvalue * 10.24)
  	print(" ==> to change for dimmer " .. tostring(dvalue) .. " new value )")
  	commandArray['OpenURL']='http://' .. Url_espdimmer.. '/control?cmd=PWM,2,' .. tostring(dvalue) .. ' '
end
return commandArray 
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
stedew
Posts: 3
Joined: Tuesday 24 November 2015 8:19
Target OS: Windows
Domoticz version:
Contact:

Re: LUA dimmer resend last setpoint

Post by stedew »

Hello simonrg,

The code i wrote is zero,zip,nada....the work is (being) done by these guy's:
http://www.esp8266.nu/index.php/Main_Page
I use a ESP-12 breakout (original loaded with lua)
First i tested with curl the commands...helps before you start coding.
The ESP is not my main target for domoticz (i use the excellent Mysensors) but it is a great test and demo platform. And the ESPeasy is quit mature i think (so far)

Good tip for the json (i already try another querry but no luck)
seems that otherdevices_svalue retrieved the value from the "data" field. there are three states possible:

State sValue
-"Off" 0 (tostring(otherdevices_svalues['Virtual2']) evaluates to 0)
-"On" 0 ( tostring(otherdevices_svalues['Virtual2']) evaluates to 0)
- "Set Level: 13 %" 0 (tostring(otherdevices_svalues['Virtual2']) evaluates to 13)




So i need to differentiate the behavior off the script to this but in JSON the level is always kept so when i could read the "level" or "Levelnt"

Code: Select all

 "Image" : "Light",
 "IsSubDevice" : false,
 "LastUpdate" : "2016-02-24 21:04:28",
 "Level" : 19,
 "LevelInt" : 19,
 "MaxDimLevel" : 100,
 "Name" : "Virtual2",....
.
.
 "Status" : "On",
 "StrParam1" : "",


The problem is solved without adding needles complexity .
So Shoot !!!
Regards,
Stefan.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest