Volume control with dummy.  [Solved]

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

Moderator: leecollings

Post Reply
Johan1974
Posts: 37
Joined: Monday 04 December 2017 20:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Volume control with dummy.

Post 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.?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Volume control with dummy.

Post 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
} 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Johan1974
Posts: 37
Joined: Monday 04 December 2017 20:56
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Volume control with dummy.  [Solved]

Post by Johan1974 »

Yeah,

Thanks waaren, it works :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest