Page 1 of 1

How to change the volume of the amixer With a virtual dimmer

Posted: Monday 01 June 2020 19:40
by besix
I have domoticz v 2020.2 beta current RPI, dzVents Version: 3.0.8
I use a USB audio card where I do volume control using the selector and sh scripts

#!/bin/bash
amixer sset 'Speaker' 2dB+

#!/bin/bash
amixer sset 'Speaker' 2dB-


or

amixer sset 'Speaker' 0% - selector - level 1

amixer sset 'Speaker' 100% - selector - level 10

How to change the volume of the amixer With a virtual dimmer.

What is the best way to do this ; amixer sset Speaker value to virtual dimmer%

Of course, it's best at dzVents
thank you for your help

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Monday 01 June 2020 20:28
by waaren
besix wrote: Monday 01 June 2020 19:40 amixer sset 'Speaker' 2dB+
How to change the volume of the amixer With a virtual dimmer.
Can you check if the dzVents command os.execute("amixer sset 'Speaker' 2dB+") does work ?

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Monday 01 June 2020 21:30
by besix
That's how it works

Code: Select all

return {
    on = {
          devices = {'Button'}
},
   logging =   
    {
        level = domoticz.LOG_DEBUG, 
        marker = 'Volume up button ',
    },
    execute = function(dz, device)
    
      if (device.state == 'On' ) then
      os.execute("amixer sset 'Speaker' 2dB+")
      dz.log ('volume up +2dB') 
     
    end
end
}

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Monday 01 June 2020 22:25
by waaren
besix wrote: Monday 01 June 2020 21:30 That's how it works
os.execute("amixer sset 'Speaker' 2dB+")
And what is the range of the dB+ and dB- ?

In other words if the slider of the dimmer goes from 0 to 100 how much should the dB do ?

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Monday 01 June 2020 22:42
by besix
Speaker [dB gain: -45,00, -45,00] - mute 0%
Speaker [dB gain: 0,00, 0,00] - full 100%

if gain = -45 and amixer sset 'Speaker' 2dB+
set gain = -43

I hope it's readable

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Monday 01 June 2020 22:51
by waaren
besix wrote: Monday 01 June 2020 22:42 Speaker [dB gain: -45,00, -45,00] - mute 0%
Speaker [dB gain: 0,00, 0,00] - full 100%

if gain = -45 and amixer sset 'Speaker' 2dB+
set gain = -43

I hope it's readable
So 100 = 0 and -45 = 0 ?

Is my conclusion that every 100/45 point of the dimmer is 1 dB correct ?

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Monday 01 June 2020 22:54
by besix
Yes, this is it

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Tuesday 02 June 2020 9:46
by besix
I changed sh scripts to one dzVents script and it works

Code: Select all

return {
    on = {
          devices = {'Volume'} -- Name of the dummy Domoticz selector
},
   logging =   
    {
        level = domoticz.LOG_DEBUG, 
        marker = 'Volume control ',
    },
    execute = function(dz, device)
	
	  local  vol = dz.devices('Volume')
	  	
	  if vol.state == 'Off' then
         os.execute('mpc pause')
         dz.log ('volume mute') 
      
	  elseif vol.state ~= 'Off' then
	     os.execute('mpc play')
	     dz.log ('Set volume to selector level')
	     end
	  if vol.state == '25%' then
	     os.execute("amixer sset 'Speaker' 25%")
	  
	   elseif vol.state == '27%' then
	     os.execute("amixer sset 'Speaker' 27%")
	  
	   elseif vol.state == '30%' then
	     os.execute("amixer sset 'Speaker' 30%")
	     
	   elseif vol.state == '35%' then
	     os.execute("amixer sset 'Speaker' 35%") 
	     
	   elseif vol.state == '40%' then
	     os.execute("amixer sset 'Speaker' 40%")
	  
	   elseif vol.state == '45%' then
	     os.execute("amixer sset 'Speaker' 45%")
	     
	   elseif vol.state == '60%' then
	     os.execute("amixer sset 'Speaker' 61%") 
	     
	   elseif vol.state == '70%' then
	     os.execute("amixer sset 'Speaker' 70%")
	  
	   elseif vol.state == '80%' then
	     os.execute("amixer sset 'Speaker' 80%")
	     
	   elseif vol.state == '95%' then
	     os.execute("amixer sset 'Speaker' 95%")   
	  end
end
}
However, this does not give as much opportunity as a dimmer

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Tuesday 02 June 2020 12:31
by waaren
besix wrote: Tuesday 02 June 2020 9:46 I changed sh scripts to one dzVents script and it works
However, this does not give as much opportunity as a dimmer
can you try this after setting up a virtual dimmer in domoticz

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'Dimmer', -- Name of the virtual  dimmer
        },
    },
    
   logging =   
    {
        level = domoticz.LOG_DEBUG, 
        marker = 'Volume control ',
    },
    
    execute = function(dz, item)

        local percentage = 0

        if item.state == 'Off' then
            os.execute('mpc pause')
            dz.log ('volume mute')
            return
        elseif item.state == 'On' then 
            percentage = 95
        else
            percentage = item.level
        end

        dz.log ('volume to ' .. percentage .. '%',dz.LOG_DEBUG)
        os.execute("amixer sset 'Speaker' " .. tostring(percentage) .. "%")
    end
}

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Tuesday 02 June 2020 14:44
by besix
Thank you for your help, but it doesn't work ok.
I added the mpc play command because dimmer did not start playback.
The script works so that it always sets the value of percentage max
no matter where the slider is

Code: Select all

  if item.state == 'Off' then
            os.execute('mpc pause')
            dz.log ('volume mute')
            return
        elseif item.state == 'On' then 
            os.execute('mpc play')
            percentage = 40
        else
            percentage = item.level
        end

        dz.log ('volume to ' .. percentage .. '%',dz.LOG_DEBUG)
        os.execute("amixer sset 'Speaker' " .. tostring(percentage) .. "%")
    end
}
Record in Log

Code: Select all

2020-06-02 14:25:41.210 Status: dzVents: Info: Volume control : volume mute
2020-06-02 14:25:41.210 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
2020-06-02 14:25:45.941 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:25:45.963 Status: dzVents: Info: Volume control : volume mute
2020-06-02 14:25:45.963 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
2020-06-02 14:25:48.814 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:25:48.844 Status: dzVents: Debug: Volume control : volume to 40%
2020-06-02 14:25:48.871 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
2020-06-02 14:25:50.993 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:25:51.016 Status: dzVents: Debug: Volume control : volume to 40%
2020-06-02 14:25:51.051 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
2020-06-02 14:25:52.715 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:25:52.737 Status: dzVents: Debug: Volume control : volume to 40%
2020-06-02 14:25:52.763 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
2020-06-02 14:25:54.105 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:25:54.128 Status: dzVents: Debug: Volume control : volume to 40%
2020-06-02 14:25:54.158 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
2020-06-02 14:25:55.345 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:25:55.368 Status: dzVents: Debug: Volume control : volume to 40%
2020-06-02 14:25:55.401 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
2020-06-02 14:25:56.650 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:25:56.672 Status: dzVents: Debug: Volume control : volume to 40%
2020-06-02 14:25:56.698 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
Here max 95 as you did

Code: Select all

  execute = function(dz, item)

        local percentage = 0

        if item.state == 'Off' then
            os.execute('mpc pause')
            dz.log ('volume mute')
            
		elseif item.state == 'On' then 
            percentage = 95
        else
            percentage = item.level
        end

        dz.log ('volume to ' .. percentage .. '%',dz.LOG_DEBUG)
        os.execute("amixer sset 'Speaker' " .. tostring(percentage) .. "%")
    end
}
And Log

Code: Select all

2020-06-02 14:54:00.174 Status: dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/Volume dimmer.lua
2020-06-02 14:54:12.030 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:54:12.064 Status: dzVents: Info: Volume control : volume mute
2020-06-02 14:54:12.064 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
2020-06-02 14:54:15.143 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:54:15.176 Status: dzVents: Debug: Volume control : volume to 95%
2020-06-02 14:54:15.205 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
2020-06-02 14:54:16.162 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:54:16.185 Status: dzVents: Debug: Volume control : volume to 95%
2020-06-02 14:54:16.212 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
2020-06-02 14:54:16.833 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:54:16.862 Status: dzVents: Debug: Volume control : volume to 95%
2020-06-02 14:54:16.890 Status: dzVents: Info: Volume control : ------ Finished Volume dimmer
2020-06-02 14:54:17.637 Status: dzVents: Info: Volume control : ------ Start internal script: Volume dimmer: Device: "Głośność (Pomocnicze)", Index: 320
2020-06-02 14:54:17.668 Status: dzVents: Debug: Volume control : volume to 95%

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Tuesday 02 June 2020 15:39
by waaren
besix wrote: Tuesday 02 June 2020 14:44 Thank you for your help, but it doesn't work ok.
I added the mpc play command because dimmer did not start playback.
Can you try with this one ?

Code: Select all

return
{
    on = 
    {
        devices = 
        {
            'Dimmer', -- Name of the virtual  dimmer
        },
    },
    
   logging =   
    {
        level = domoticz.LOG_DEBUG, 
        marker = 'Volume control ',
    },
    
    execute = function(dz, item)
        if item.state == 'Off' then
            os.execute('mpc pause')
            dz.log ('volume mute')
            item.dimTo(1).silent()
            item.dimTo(0).silent().afterSec(1)
        else    
            local percentage = item.level
            dz.log ('volume to ' .. percentage .. '%',dz.LOG_DEBUG)
            os.execute("mpc play; sleep 1; amixer sset 'Speaker' " .. tostring(percentage) .. "%")
        end
    end
}

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Tuesday 02 June 2020 18:38
by besix
Now works in the slider range.
The level change works with a second delay but it is probably by sleep 1? I have a question
Why when the dimmer is OFF need to set the dimmer to 1 and per second to 0
Second question After setting the dimmer to OFF and then He is always 1% level Does it have to be this way?
Third question. If you delete the mpc play and pausa commands, you can eliminate delays?
Many thanks for your time and help

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Tuesday 02 June 2020 18:44
by waaren
besix wrote: Tuesday 02 June 2020 18:38 Now works in the slider range.
The level change works with a second delay but it is probably by sleep 1? I have a question
Why when the dimmer is OFF need to set the dimmer to 1 and per second to 0
Second question After setting the dimmer to OFF and then He is always 1% level Does it have to be this way?
Answer 1+2: If you don't do this the slider will stay on the last level ==>> visual confusing
Third question. If you delete the mpc play and pausa commands, you can eliminate delays?
Yes, the sleep is only to ensure that the volume command does not interfere with the play.
Just experiment without it and you will see if it keeps working. I cannot test because I don't own the hardware.

Re: How to change the volume of the amixer With a virtual dimmer

Posted: Tuesday 02 June 2020 18:47
by besix
Thank you again !

Re: How to change the volume of the amixer With a virtual dimmer  [Solved]

Posted: Tuesday 02 June 2020 21:13
by besix
Without mpc play support, pause Works as I wanted
waaren
You were very helpful