Sonos - Timer Sensor

Recently I’ve been using the Sleep Timer more on my Sonos speakers and appreciate being able to set the timer from Home Assistant. Sort of annoyingly the timer information doesn’t seem to be available from within Home Assistant as either a standalone sensor or speaker attribute.

Digging through the code a bit I noticed that the Sonos integration utilizes the SoCo library. There is a function to return the sleep timer information as part of that library. I’m curious if there is a technical reason this isn’t available in HA or if it’s just never been integrated? Really appreciate how well integrated the rest of the components are so figured there must be some story about why this is missing.

We could add it. Give me a use case or two on how you would use it.

Thanks for the response!

As far as use cases the most obvious one is just to see how much time is remaining. You can set the timer from within HA but after that if you want to check on the remaining time you have to jump back over to the Sonos app. Just doesn’t make for the best user experience (plus the Sonos app is horrible). Often I’ll set a timer for an hour and then want to extend it if I can’t fall asleep. Instead of just being able to see “there is 10 min left” I have to do the mental calculations in my head based on when I think I started it or fire up the Sonos app and dig through the menus to see the remaining time. If it the value was within HA I could just put it on the dashboard I use for our bedroom. It would also be available as an additional item for a small e-ink display I have as well.

I can envision a lot more advanced use cases too where you could have an automation automatically extend the time based on other sensors. For example, if the timer has less than 10 minutes but lights are still on, extend time 15 more minutes (keep music playing while awake reading or something). Or if lights go off and timer has less than 5 minutes left do nothing, but more than 10 minutes reset the timer to 5 (essentially stop music when going to bed).

I did find a workaround for this but it is not the best. It involves setting up a Timer helper and then triggering that in any automation that sets the Sonos timer. This does work but seems a bit hacky, plus if the timer is modified from within the Sonos app directly it doesn’t match HA anymore. I can’t entirely control what other people in the house will do and sometimes they’ll use the Sonos app since it provides a countdown visual. If HA had a reliable sensor value I could probably get everyone to use HA exclusively.

Thanks for considering this. P.S. - if you do implement can you post a link to the PR here? I’d like to see how the code was modified. I dug through the repo myself but the flow was not intuitive to me. I know Python but the learning curve seemed too steep to try myself on this one.