Page 1 of 1

Volume control with dummy.

Posted: Thursday 11 February 2021 21:41
by Johan1974
I am using the following script:

Code: Select all

 return {
	on = {
		devices = { 'Radio' },
		timer = { 'every 5 minutes' },
		},
		
	execute = function(domoticz, device)
	    		
		if device.state ~= 'Off' then
			if device.state == 'Q-Music' then
				os.execute ("killall mplayer")
				os.execute ("mplayer -noconsolecontrols http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3 -volume 100 &> /dev/null")
			end
		end
	end

} 
Now I have made a Dummy (0-100%) called 'Volume' and try to control volume of the playing stream.
Script changed to:

Code: Select all

 return {
	on = {
		devices = { 'Radio','Volume' },
		timer = { 'every 5 minutes' },
		},
		
	execute = function(domoticz, device)
	    local setpoint = domoticz.devices('Volume')
	
		
		if device.state ~= 'Off' then
			if device.state == 'Q-Music' then
				os.execute ("killall mplayer")
				os.execute ("mplayer -noconsolecontrols http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3 -volume (setpoint.level) &> /dev/null")
			end
		end
	end

} 
But this is not working. Does anyone have an idea.?

Re: Volume control with dummy.

Posted: Thursday 11 February 2021 22:49
by waaren
Johan1974 wrote: Thursday 11 February 2021 21:41 I have made a Dummy (0-100%) called 'Volume' and try to control volume of the playing stream.
But this is not working. Does anyone have an idea.?
Can you try this one ?

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Radio',
            'Volume',
        },
        timer =
        {
            'every 5 minutes',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,  -- change to domoticz.LOG_ERROR if all OK
        marker = 'Q-music',
    },

    execute = function(dz)
        local setpoint = dz.devices('Volume')
        local radio = dz.devices('Radio')

        if setpoint.state ~= 'Off' then
            if radio.state == 'Q-Music' then
                os.execute ("killall mplayer")
                os.execute ("mplayer -noconsolecontrols http://icecast-qmusic.cdp.triple-it.nl/Qmusic_nl_live_96.mp3 -volume " .. setpoint.level .. " &> /dev/null")
            end
        end
    end
} 

Re: Volume control with dummy.  [Solved]

Posted: Tuesday 16 February 2021 19:14
by Johan1974
Yeah,

Thanks waaren, it works :)