Slider change or on/off button change

Easy to use, 100% Lua-based event scripting framework.
Post Reply
pvklink
Posts: 111
Joined: Wednesday 12 November 2014 16:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

Slider change or on/off button change

Post by pvklink » Wednesday 14 March 2018 22:49

I have finished my first upgrade from LUA to dzvents scipt
I only have one issue left.
I have a switch with volumeslider. With lua it was
if (devicechanged[RECEIVER_VOLUME] == 'On') then .. do things belonging to on button
Elsif (devicechanged[RECEIVER_VOLUME] == 'Off') then do things belonging to off button
Else was a volume change...

I tried to migrate this, but only ON or OFF works and a volume change does not work, it takes the current_state on or off!
Someone an idea ?
i marked the else tree where the volumechange was coded with: --- FROM HERE IT DOES NOT WORK WHEN VOLUME IS CHANGED

Code: Select all

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

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

    local TVSTATUS = domoticz.devices('tv')                                                                 -- switch met tv status   
    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 IPTV = domoticz.variables('iptv').value                                                           -- ip adress tv
    
    local DENONSTATUS = domoticz.variables('denonstatus')                                                   -- USER variabele in domoticz waar DENON status wordt bijgehouden
    local MAXLEVEL = 30                                                                                     -- MAximaal volume DENON
    
    domoticz.log('PRG: ' ..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: ' ..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: ' ..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: ' ..scriptnaam ..': denon op radio gezet')                                           -- debugging
            
        else                                                                                                    --TV heeft geen status
            domoticz.log('PRG: ' ..scriptnaam ..': Geen tv status bekend')                                      -- debugging    
            
        end 
        
    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: ' ..scriptnaam ..': denon is uitgezet')                                              -- debugging   

   --- FROM HERE IT DOES NOT WORK WHEN VOLUME IS CHANGED     

    else                                                                                                    -- denon VOLUME wordt veranderd
        domoticz.log('PRG: ' ..scriptnaam ..': VOLUME aangepast')                                              -- debugging   
        
         if (DENONSTATUS == 'Off') then                                                                     -- als denon uitstaat
            os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON" );        -- zet denon aan
            DENONSTATUS.set('On')                                                                               -- zet uservariabele aan
            
    	    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: ' ..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: ' ..scriptnaam ..': denon op radio gezet')                                       -- debugging
                
            else                                                                                                --TV heeft geen status
                domoticz.log('PRG: ' ..scriptnaam ..': Geen tv status bekend')                                      -- debugging    
                
            end 
        end
        NewLevel = RECEIVER_VOLUME.volume - 80 ;                                                            -- Apply offset from absolute to relative
        
        if tonumber(NewLevel) > MAXLEVEL then                                                               -- Peter toegevoegd volume maxlevel
            NewLevel = MAXLEVEL                                                                               -- maximaal geluidsniveau nog checken of dit wel werkt met math.min constructie        
        end                                                                                                 -- einde toevoeging maxvolume
        
        os.execute ("curl http://" .. (IP) .. "/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/" .. (NewLevel)); --set volume
        domoticz.log('PRG: ' ..scriptnaam .. 'Device:' .. RECEIVER_VOLUME .. ' send command Mute = Off; Set Volume = ' .. NewLevel)                                              -- debugging    
    end
end
}

dannybloe
Posts: 1480
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Slider change or on/off button change

Post by dannybloe » Wednesday 14 March 2018 23:44

Can you isolate the problem and reduce it to a simple example? This script is way too long to disect and figure out what’s wrong.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

User avatar
waaren
Posts: 1100
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Slider change or on/off button change

Post by waaren » Thursday 15 March 2018 14:01

@pvklink Are you sure state can have other values then "On" and "Off" ?

To debug I would add

Code: Select all

print("***********************")
print("RECEIVER_VOLUME.state: " .. RECEIVER_VOLUME.state)

print("***********************  start DUMP")
RECEIVER_VOLUME.dump()
print("***********************  end DUMP")

just before the

Code: Select all

if (RECEIVER_VOLUME.state == 'On') then
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests