Script trigger does not work. Why?

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Scaevola
Posts: 7
Joined: Saturday 09 November 2019 20:36
Target OS: Linux
Domoticz version:
Contact:

Script trigger does not work. Why?

Post by Scaevola »

Hello everyone,
I've got a ceiling LEDs connected to the ESPEasy and MOSFET. I have a nice slider in Domoticz, that works well.

Code: Select all

-- LED dimmer script script using ESPEasy

commandArray = {}
DomDevice = 'ESP_dimmer';
IP = '192.168.0.108';
PIN = "2";
if devicechanged[DomDevice] then
   if(devicechanged[DomDevice]=='Off') then
		print ("OFF dim = "..uservariables['dimmer']);
		CalcValue = 0;
   	else if(devicechanged[DomDevice]=='On') then
   		DomValue = uservariables['dimmer'];
        print ("ON dim = "..uservariables['dimmer']);
        CalcValue = DomValue;
    else
    	print("Other");
        DomValue = otherdevices_svalues[DomDevice];
        CalcValue = math.floor(DomValue / 100 * 1023);
        commandArray['Variable:dimmer'] = tostring(CalcValue);
        print ("dim Level = "..uservariables['dimmer']);
   	end
   	end
   	runcommand = "curl 'http://" .. IP .. "/control?cmd=PWM,"  ..PIN.. "," .. CalcValue .. ",500'";
   	os.execute(runcommand);
	print("PWM value= "..CalcValue);
end
return commandArray
However, I try to automate the dimming by discovering Philips TV being turned on (by pings). I created also a virtual device, that changes the state of the switch depends on TV state.
But there are some bumps:
I try to release the dimming by the TV, but, despite the TV state is discovered well (the log says the tv is on or off), I can't make the dimmer work with that.
I tried a blockly scheme without success.
blockly.png
blockly.png (17.17 KiB) Viewed 308 times
Then I tried a dzVents script, also without succes.

Code: Select all

return {
   	on = {
		devices = {'Telewizor_Philips','ESP_dimmer'	}
		},
	
	execute = function(domoticz, Telewizor_Philips)
	     if Telewizor_Philips.state==('On') then
	       commandArray['Scene:Brighten_LED']='On'
	        domoticz.log('Light dimmed - TV on ')
        else
         commandArray['Scene:Dim_LED']='On'
	        domoticz.log('Light brighten - tv off ')
	    end 
	end
}
return commandArray
What I am doing wrong?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script trigger does not work. Why?

Post by waaren »

Scaevola wrote: Tuesday 24 November 2020 20:44 I've got a ceiling LEDs connected to the ESPEasy and MOSFET. I have a nice slider in Domoticz, that works well.

Then I tried a dzVents script, also without succes.
What I am doing wrong?
You should have seen some errors in the log because you mix classic Lua with dzVents.

You could try below script but please first take some minutes to read this.
_________________________________________________________________________________________________________________________
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
___________________________________________________________________________________________________________________________

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Telewizor_Philips',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Philips TV',
    },

    execute = function(dz, item)
        dz.log(item.name .. ', state: ' .. item.state, dz.LOG_DEBUG )
        if item.state == 'On' then
            dz.scenes('Brighten_LED').switchOn()
            dz.log('Light dimmed - TV on ', dz.LOG_DEBUG)
        else
            dz.scenes('Dim_LED').switchOn()
            dz.log('Light brighten - tv off ', dz.LOG_DEBUG)
        end
    end
}
.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Scaevola
Posts: 7
Joined: Saturday 09 November 2019 20:36
Target OS: Linux
Domoticz version:
Contact:

Re: Script trigger does not work. Why?

Post by Scaevola »

Ok. Thank you. The syntax of dzVents is very odd to me. I try to understand it, but it's quite different from other programming languages.
And do you know why the blockly scheme did not work?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script trigger does not work. Why?

Post by waaren »

Scaevola wrote: Thursday 26 November 2020 11:15 Ok. Thank you. The syntax of dzVents is very odd to me. I try to understand it, but it's quite different from other programming languages.
I am sure you will get up to speed quickly with dzVents if you are used to other programming languages once you start playing with the many examples on this forum.
dzVents is 100% Lua and on the internet there is an enormous amount of useful information about Lua.

[/quote]And do you know why the blockly scheme did not work?[/quote]No.
Did you store the Blockly as being device triggered?
Do you see anything in the domoticz log when changing the state of the virtual switch?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest