Problems converting LUA to DZVENTZ

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

Moderator: leecollings

Post Reply
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Problems converting LUA to DZVENTZ

Post by pvklink »

Hi i have several LUA scripts to manage my denon receiver with http commands.
The receiver is always in sleeping mode, i manually manage it state by a uservariable.

I recently started to convert to DZVENTZ and getting rid of LUA...
I have a two scripts:
1. denon_volume (dimmer) for on/off and volume changing
2. denon_source for selecting the source. WITH LUA i had no problems but with dzventz i still have some problems.

When denon is in sleeping state, and selecting a source (like radio), my denon_source turns the receiver on, selects the source, so far so good!
But the domoticz device denon_volume is still off. I dont understand this because i do call to dz.devices['denon_volume'].switchOn(). With LUA scripts this part was working....
When i can activate the dimmer switch from denon_source i can get rid of the uservariables and read the state of this dimmer for on/off

denon_source

Code: Select all

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

    logging = { level   = domoticz.LOG_DEBUG ,marker  = actOnIdleDevices },

	execute = function(dz, device)

	--domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)

    local scriptnaam        = 'testsource'
    local receiver_source   = dz.devices('denon_source')                                                                 
    local receiver_volume   = dz.devices('denon_volume')
    local ip                = dz.variables('ipdenon').value                                                        
    local denonstatus       = dz.variables('denonstatus')                                                  

    if receiver_source.state == 'FM RADIO' then                -- selector 10
        SourceToSet = 'TUNER';
    elseif receiver_source.state == 'TV ZIGGO' then     -- selector 10
        SourceToSet = 'SAT/CBL';
    elseif receiver_source.state == 'SONOS' then         -- selector 30
        SourceToSet = 'CD';
    elseif receiver_source.state == 'KODI MCE' then         -- selector 40
        SourceToSet = 'MPLAY';
    elseif receiver_source.state == 'PC KABEL' then         -- selector 50
        SourceToSet = 'GAME';
    elseif receiver_source.state == 'CHROMECAST' then        -- selector 60
        SourceToSet = 'BD';
    else 
        SourceToSet = 'Unknown';
    end

    if ( SourceToSet == 'Unknown' ) then
        -- do nothing
    else                                                                                                -- Denon wordt op Source gezet nog aanpassen check denon aan ?
        if denonstatus== 'Off' then                                                 -- als denon uitstaat
            dz.devices['denon_volume'].switchOn()  --my denon goes on, but not the denon_volume switch
        end
        os.execute ("curl http://" .. (ip) .. "/MainZone/index.put.asp?cmd0=PutZone_InputFunction%2F" .. (SourceToSet) );   -- Denon wordt op source gezet
        --denonstatus.set('On') 
    end
    dz.log("Script: " .. scriptnaam .. " Device:" .. receiver_source.state .. " set source input = " .. (SourceToSet) .. ". => " .. receiver_source.state)
end
}

denon_volume

Code: Select all

return {
   active = true,
	on = {
		devices = {
			'denon_volume'
		}
	},

execute = function(domoticz, RECEIVER_VOLUME)
    local scriptnaam = 'dztest_volume'

    local TVSTATUS = domoticz.devices('tv-woonkamer')                                                       -- switch met tv status       TVSTATUS=os.execute('ping -c 1 192.168.20.24') duurt te lang, dus ping-service gebruikt
    local RECEIVER_SOURCE = domoticz.devices('denon_source')                                                -- switch met DENON devices
    local RECEIVER_MIXER = domoticz.devices('denon_mixer')                                                  -- switch met DENON mixer
    local RADIO_SENDER = 'denon_radio'                                                                      -- switch met DENON radio zender

    local IP = domoticz.variables('ipdenon').value                                                          -- ip adress denon receiver, 
    local IPTV = domoticz.variables('iptv').value                                                           -- ip adress tv
    local DENONSTATUS = domoticz.variables('denonstatus')                                                   -- USER variabele in domoticz waar DENON status wordt bijgehouden
    local MAXLEVEL = 50                                                                                     -- MAximaal volume DENON
    local DEFLEVEL = 20                                                                                     -- Default volume DENON
    local XOLDVOLUME = domoticz.variables('denonvolume')                                                    -- opgeslagen volume
    local OLDVOLUME =XOLDVOLUME.value                                                                       -- ip adress denon receiver, niet nodig ping service van domoticz wordt gebruikt
    local RVOLUME = RECEIVER_VOLUME.level                                                                   -- Apply offset from absolute to relative
    local VOLUME = RVOLUME
    local VOLCOR = 80
    
    domoticz.log('PRG: 1 ' ..scriptnaam ..' tv:' .. IPTV .. ' Status:' .. TVSTATUS.state)                     -- voor debugging

    if (RECEIVER_VOLUME.state == 'On') then                                                                 -- denon wordt AAN gezet
        os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON" );            -- zet denon aan
        DENONSTATUS.set('On')                                                                                   -- zet uservariabele aan
        domoticz.log('PRG: 2 ' ..scriptnaam ..': denon is aangezet')                                              -- debugging 

	    if (TVSTATUS.state == 'On') then                                                                        --TV staat AAN
            --RECEIVER_SOURCE.switchSelector(20)                                                                      -- zet versterker op tv             .afterSec(2)
            --RECEIVER_MIXER.switchSelector(10)                                                                     -- set versterker op stereo
            domoticz.log('PRG: 3 ' ..scriptnaam ..': denon op tv gezet')                                              -- debugging    

        elseif (TVSTATUS.state == 'Off') then                                                                   --TV staat UIT
            --RECEIVER_SOURCE.switchSelector(10)                                                                      -- zet versterker op RADIO         .afterSec(2)
            --RADIO_SENDER.switchSelector(10)                                                                       -- set radio zender sky
            --RECEIVER_MIXER.switchSelector(20)                                                                     -- set versterker op mch stereo
            domoticz.log('PRG: 4 ' ..scriptnaam ..': denon op radio gezet')                                           -- debugging
            
        else                                                                                                    --TV heeft geen status
            domoticz.log('PRG: 5 ' ..scriptnaam ..': Geen tv status bekend')                                      -- debugging    
            
        end 

        if (RVOLUME == OLDVOLUME) then 
            VOLUME=DEFLEVEL
        
        elseif tonumber(RVOLUME) == 0 then                                             -- als slidergeluid = opgeslagen geluid
            VOLUME=DEFLEVEL
        
        end

        if tonumber(VOLUME) > MAXLEVEL then                                                                  -- Peter toegevoegd volume maxlevel
            VOLUME = MAXLEVEL                                                                                   
        end

        os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/" .. (VOLUME-VOLCOR)); --set volume
        XOLDVOLUME.set(VOLUME)                                                                              -- zet uservariabele aan        --RECEIVER_VOLUME.switchSelector(VOLUME)
        domoticz.log('PRG: 6 ' ..scriptnaam .. ' VOLUME aangepast: Slidervolume:' .. tostring(RVOLUME) .. ' Oldvolume:' .. tostring(OLDVOLUME) .. ' NieuwVolume:' .. tostring(VOLUME))           -- debugging    

    elseif  (RECEIVER_VOLUME.state == 'Off') then                                                           -- denon wordt UIT gezet
        os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FOFF" );           -- zet denon uit
        DENONSTATUS.set('Off')                                                                                  -- zet uservariabele aan
        domoticz.log('PRG:7  ' ..scriptnaam ..': denon is uitgezet')                                              -- debugging   
    end 
 
end
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problems converting LUA to DZVENTZ

Post by waaren »

pvklink wrote: Tuesday 11 December 2018 20:22 I dont understand this because i do call to dz.devices['denon_volume'].switchOn()
try changing

Code: Select all

dz.devices['denon_volume'] 
to

Code: Select all

dz.devices('denon_volume')
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: Problems converting LUA to DZVENTZ

Post by pvklink »

I have rewritten all my denon scripts, All dzventz now instead of LUA. I also eliminated uservariables etc. Problems are gone now...
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest