ol-iver / denonavr

Automation Library for Denon AVR receivers.
MIT License
176 stars 67 forks source link

Q: Get/Set status of sleep timer? #100

Closed Sirs0ri closed 4 years ago

Sirs0ri commented 5 years ago

Hi folks, I was wondering if there is a reason the SLP command isn't implemented? I'd like to be able to eventually monitor my AVRs internal sleep timer in homeassistant and react to it.

By playing around with the library I noticed that myDenonavr.send_get_command("/goform/formiPhoneAppDirect.xml?SLP020") works fine to set the timer to 20min, I feel like reading the current value shouldn't be much difficult, but I can't get it to work myself unfortunately.

Thanks so much for creating this awesome library! I appreciate any help I can get.

JPHutchins commented 5 years ago

Hello! Send your GET request to this endpoint goform/formiPhoneAppSleepTimer.xml like: myDenonavr.send_get_command("/goform/formiPhoneAppSleepTimer.xml") and you will receive an XML tree like this in response:

<item>
  <SleepTimer>
    <value>019</value>
  </SleepTimer>
</item>

where the value of the value field is the remaining time in your sleep timer. You can do a sanity check by performing that GET request from browser, navigate to: http:///goform/formiPhoneAppSleepTimer.xml

It is none of my business, but assuming that you are synchronizing with a light dimming or other component shutdown, it may make more sense to implement the sleep timer itself in Home Assistant for a more general approach. In this manner you could state "Hey Google, set sleep timer for 20 minutes" in a fatigued manner and let HA manage the states of various entities like the Denon.

https://www.home-assistant.io/components/timer/ Have fun and feel free to submit PR for addition of that sleep timer command. Cheers, J.P.

ghost commented 5 years ago

But is any chance to add option setup sleep in Home Assistant to Denon ? For zone 1 and zone 2.... This will be a good features.

JPHutchins commented 5 years ago

To your configuration.yaml add:

timer:
  zone1:
    duration: '00:20:00'
  zone2:
    duration: '00:20:00'

And to automations.yaml add:

# Example automations.yaml entry
- alias: Zone 1 Sleep Timer
  id: zone1Sleep
  action:
  - service: timer.start
    entity_id: timer.zone1

# When timer is stopped, the time run out, turn off Denon
- alias: zone1SleepStop
  id: zone1SleepStop
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.zone1
  action:
  - service: media_player.turn_off
    data:
      entity_id: media_player.<your denon entity name>

Please refer to https://www.home-assistant.io/components/timer/ You will have available to you an "automation switch" called Zone 1 Sleep Timer that can be added to frontend.

On my to-do list is to make a new component for Home Assistant, av_receiver, since these devices have very few overlaps with the media players covered by the media_player component. For example, Home Assistant does not recognize "zones" or "sleep" for a media player while it would be simple in Denon to independently control the power of the zones or sleep. So HA needs a new component.

Furthermore, the timer component does seem a bit weak as it does not provide a countdown feedback so that is another area for improvement.

I strongly recommend HA for automation and timing schemes.

If you would rather add to denonavr library then try this command: Zone 2, sleep in 10 minutes: GET /goform/formiPhoneAppDirect.xml?Z2SLP010 Generally: GET /goform/formiPhoneAppDirect.xml?Z{int Zone number}SLP{minutes in 3 digits} I do not know if values other than 10s are valid, try it out. From what I can tell it does not support seeing different Sleep Timer values so it may not support multiple unique sleep timers per zone - but Home Assistant can take care of that.

I will look into a stop gap - implement a "generic library command" in HA media_player where user can call a service and include in the data a library command such as turning zones on and off independently.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.