GMFalka
(Gm Falka)
March 31, 2019, 10:44am
1
Hello!
I’m trying to make an appdaemon for an IR remote to control my snapcast, but for some reason, the “is_volume_muted” doesnt like IF statements.
If i try the below code with anything else (like volume_level
) it works!
Heres the code:
if self.get_state("sensor.ir_black_remote") == "8F79A65": #Play/Pause
muted = self.get_state("player", attribute= "is_volume_muted")
if muted == "false":
self.call_service("media_player/volume_mute", entity_id = "player", is_volume_muted = "true")
if i print muted
it says “False” (with capital F), so i tried with that but no luck.
(No idea why its capitalized, the original sensor attribute is “false”)
Any help would be appreciated
The “player” in this line of code needs to be the full entity name, like media_player.player or whatever it is called in your setup.
muted = self.get_state(“player”, attribute= “is_volume_muted”)
The same goes for the line below
self.call_service(“media_player/volume_mute”, entity_id = “player”, is_volume_muted = “true”)
GMFalka
(Gm Falka)
March 31, 2019, 11:27am
3
Yes, i know. “player
” is stated somewhere else.
If i use the full entity name right in the IF statement, it still doesnt work with “is_volume_muted
”
What do you mean “player” is stated somewhere else? Do you have a variable like player = media_player.player
? If so then it should not be put between quotation marks.
If you use the full entity name in the below line of code, what is the result when the player is muted and when it is not muted?
self.get_state(“player”, attribute= “is_volume_muted”)
GMFalka
(Gm Falka)
March 31, 2019, 11:57am
5
I know the “player” part is working because if i change “is_volume_muted” to “volume_level” everything works.
self.get_state(“player”, attribute= “is_volume_muted”)
Prints “False”.
It prints “False” when the volume is not muted and “True” when it is muted?
If so then you can try:
if not muted:
instead of
if muted == ‘false’
GMFalka
(Gm Falka)
March 31, 2019, 12:05pm
7
Yep. That solved it.
Thank you very much @Burningstone !
Glad I was able to help.
Python recognizes True/False starting with a capital letter as boolean and it doesn’t recognize false/true as boolean.