dahlb / ha_hatch

Home Assistant Integration for Hatch Rest Mini
MIT License
76 stars 16 forks source link

Feature Request: Current favorite/sound mode in state #90

Closed ianwestcott closed 1 week ago

ianwestcott commented 5 months ago

I recently purchased a Hatch Rest+ Gen 2 and it's been a huge help in my household, thanks in large part to this integration. Thank you for writing and maintaining it!

I'm working on setting up template switches in Home Assistant for each of the "favorites" (which show as "sound modes" in the media_player entity), so I can activate each mode with a single button/action. An example switch looks like this:

---
switch:
  - platform: template
    switches:
      hatch_rest_gentle_awakening:
        friendly_name: "Hatch Rest Gentle Awakening"
        icon_template: mdi:bird
        value_template: "{{ is_state('media_player.hatch_rest',
                                     'playing') }}"
        turn_on:
          - service: media_player.select_sound_mode
            data:
              sound_mode: "Gentle Awakening-00000000"
            target:
              entity_id: media_player.hatch_rest
          - service: media_player.media_play
            data:
              entity_id: media_player.hatch_rest
        turn_off:
          service: media_player.media_stop
          data:
            entity_id: media_player.hatch_rest

One small issue I've encountered is how to render the value_template. In the example above I'm just using the state of the media_player entity. Unfortunately that turns all switches on when the media_player state is playing, regardless of what favorite is active, which prevents me from switching between favorites.

Ideally I could show the current state of each favorite separately, but that requires knowing which favorite is currently active on the Hatch Rest+. The iOS app seems to have the information about what favorite is active, so it should be possible to receive this info, but as far as I can tell the HA integration does not expose it.

Would it be possible to add the active favorite to the state of the media_player entity in Home Assistant so that I can use it to set the state of template switches? Or if this information is already available, please let me know where I can find it.

Thanks!

dahlb commented 5 months ago

I have a rest+ gen1 but the sound mode should be an attribute on the media player like rain in this screenshot Screenshot_20231210-224317.png

ianwestcott commented 5 months ago

Maybe this is an issue with the Gen 2 then? Note the missing attribute in my equivalent screenshot.

image

dahlb commented 5 months ago

@w1ll1am23 @brentdur it looks like RestoreIot never sets the audio_track field in https://github.com/dahlb/hatch_rest_api/blob/main/src/hatch_rest_api/restoreiot.py is that something either of you can help with populating?

cmerkle commented 3 months ago

I have a rest+ gen2 and I do not see a sound mode attribute in the media player entity state, so I don't see how I can even set which sound to play

volume_level: 0.95 media_content_type: music device_class: speaker friendly_name: My Rest+ Media Player supported_features: 87044

dahlb commented 1 week ago

this should all be working in version 1.18.0 sound mode allows you to pick which sound is playing and reflects the currently playing sound use select source to activate favorites, ie:

service: media_player.select_source target: entity_id: media_player.sage_reading_light_media_player data: source: Sleep list of favorites are available on media player entity, ie:

sources:

ianwestcott commented 1 week ago

@dahlb Thank you so much! I can confirm that this now works perfectly for me. Here's an updated example template switch that also takes advantage of the new auto-created scenes in 1.20.0:

---
switch:
  - platform: template
    switches:
      hatch_rest_gentle_awakening:
        friendly_name: "Hatch Rest Gentle Awakening"
        icon_template: mdi:bird
        value_template: "{{ is_state('media_player.hatch_rest',
                                     'playing') and
                            is_state_attr('media_player.hatch_rest',
                                          'sound_mode',
                                          'Birds') }}"
        turn_on:
          - service: scene.turn_on
            target:
              entity_id: scene.hatch_rest_gentle_awakening
        turn_off:
          service: media_player.media_stop
          data:
            entity_id: media_player.hatch_rest