How to change the volume of the amixer With a virtual dimmer [Solved]
Moderator: leecollings
-
- Posts: 99
- Joined: Friday 25 January 2019 11:33
- Target OS: Linux
- Domoticz version: beta
- Location: Poland
- Contact:
How to change the volume of the amixer With a virtual dimmer
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
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 99
- Joined: Friday 25 January 2019 11:33
- Target OS: Linux
- Domoticz version: beta
- Location: Poland
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer
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
}
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer
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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 99
- Joined: Friday 25 January 2019 11:33
- Target OS: Linux
- Domoticz version: beta
- Location: Poland
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer
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
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer
So 100 = 0 and -45 = 0 ?
Is my conclusion that every 100/45 point of the dimmer is 1 dB correct ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 99
- Joined: Friday 25 January 2019 11:33
- Target OS: Linux
- Domoticz version: beta
- Location: Poland
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer
Yes, this is it
-
- Posts: 99
- Joined: Friday 25 January 2019 11:33
- Target OS: Linux
- Domoticz version: beta
- Location: Poland
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer
I changed sh scripts to one dzVents script and it works
However, this does not give as much opportunity as a dimmer
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
}
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: How to change the volume of the amixer With a virtual 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 99
- Joined: Friday 25 January 2019 11:33
- Target OS: Linux
- Domoticz version: beta
- Location: Poland
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer
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
Record in Log
Here max 95 as you did
And Log
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
}
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
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
}
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%
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 99
- Joined: Friday 25 January 2019 11:33
- Target OS: Linux
- Domoticz version: beta
- Location: Poland
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer
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
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer
Answer 1+2: If you don't do this the slider will stay on the last level ==>> visual confusingbesix 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?
Yes, the sleep is only to ensure that the volume command does not interfere with the play.Third question. If you delete the mpc play and pausa commands, you can eliminate delays?
Just experiment without it and you will see if it keeps working. I cannot test because I don't own the hardware.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 99
- Joined: Friday 25 January 2019 11:33
- Target OS: Linux
- Domoticz version: beta
- Location: Poland
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer
Thank you again !
-
- Posts: 99
- Joined: Friday 25 January 2019 11:33
- Target OS: Linux
- Domoticz version: beta
- Location: Poland
- Contact:
Re: How to change the volume of the amixer With a virtual dimmer [Solved]
Without mpc play support, pause Works as I wanted
waaren
You were very helpful
waaren
You were very helpful
Who is online
Users browsing this forum: No registered users and 1 guest