@apop
With the addition of your code the control function now appears to getting called, however I get this error from app daemon:
2019-05-31 15:22:52.003746 WARNING AppDaemon: ------------------------------------------------------------
2019-05-31 15:24:37.013951 INFO audio_control: module: /config/appdaemon/apps/audio-control.py,function: control, MSG: Amp Off
2019-05-31 15:26:41.260096 INFO AppDaemon: Terminating night_volume_control
2019-05-31 15:26:41.260455 INFO AppDaemon: Reloading Module: /config/appdaemon/apps/night-volume-control.py
2019-05-31 15:26:41.261676 INFO AppDaemon: Initializing app night_volume_control using class NightVolumeControl from module night-volume-control
2019-05-31 15:26:42.264342 INFO AppDaemon: Terminating night_volume_control
2019-05-31 15:26:42.264574 INFO AppDaemon: Reloading Module: /config/appdaemon/apps/night-volume-control.py
2019-05-31 15:26:42.265848 INFO AppDaemon: Initializing app night_volume_control using class NightVolumeControl from module night-volume-control
2019-05-31 15:26:48.686788 INFO audio_control: module: /config/appdaemon/apps/audio-control.py, function: control, MSG: Amp on
2019-05-31 15:27:04.003192 INFO night_volume_control: module: /config/appdaemon/apps/night-volume-control.py, function: control, MSG: Paused registered
2019-05-31 15:27:04.003388 WARNING AppDaemon: ------------------------------------------------------------
2019-05-31 15:27:04.003659 WARNING AppDaemon: Unexpected error in worker for App night_volume_control:
2019-05-31 15:27:04.003788 WARNING AppDaemon: Worker Ags: {'name': 'night_volume_control', 'id': UUID('2dadd670-fbd3-4509-8eae-cc83f255165d'), 'type': 'attr', 'function': <bound method NightVolumeControl.control of <night-volume-control.NightVolumeControl object at 0x7f56ee66c278>>, 'attribute': 'state', 'entity': 'media_player.mpd', 'new_state': 'paused', 'old_state': 'playing', 'kwargs': {'entity': 'media_player.mpd', 'attribute': 'state', 'old_state': 'playing', 'new_state': 'paused', 'new': 'paused', 'duration': 15, 'handle': UUID('794cd5d7-c103-4033-88d7-7189a2c677c6')}}
2019-05-31 15:27:04.003891 WARNING AppDaemon: ------------------------------------------------------------
2019-05-31 15:27:04.004159 WARNING AppDaemon: Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/appdaemon/appdaemon.py", line 595, in worker
self.sanitize_state_kwargs(app, args["kwargs"]))
File "/config/appdaemon/apps/night-volume-control.py", line 13, in control
self.call_service("media_player/volume_set", entity, volume_level=.2)
File "/usr/local/lib/python3.7/site-packages/appdaemon/plugins/hass/hassapi.py", line 22, in func_wrapper
return func(*args, **kwargs)
TypeError: call_service() takes 2 positional arguments but 3 were given
Here is the full code for reference.
import appdaemon.plugins.hass.hassapi as hass
class NightVolumeControl(hass.Hass):
def initialize(self):
for media_player in self.args["entities"]:
self.listen_state(self.control, self.args["entities"], new="paused", duration=15)
self.listen_state(self.control, media_player, new ="paused", duration=15)
def control(self, entity, attribute, old, new, kwargs):
if new == "paused":
self.log("module: __module__, function: __function__, MSG: Paused registered")
self.call_service("media_player/volume_set", entity, volume_level=.2)