RogerSelwyn / Home_Assistant_SkyQ_MediaPlayer

Home Assistant SkyQ Media player component
MIT License
103 stars 17 forks source link

[Feature Request] Scheduled Recording Info #126

Closed Locoblade closed 1 year ago

Locoblade commented 1 year ago

As the Sky Q hardware is a bit of a power hog never properly hibernating below about 20w, to save power I'd like to be able to turn the box off overnight and when the house is empty using an automation. Obviously the issue is we may have something scheduled to record that would be missed if a simple time/proximity based automation was used with no knowledge of when a recording is scheduled.

I guess extracting the entire recording schedule may be difficult but is there a way you could develop a sensor to extract something as simple as the time or number of minutes until the next scheduled recording and also indicate if it was recording at the time? That way you could set an automation to power down if not recording and ensure its back on before the next scheduled recording is due to start.

Many thanks and great work on the integration

RogerSelwyn commented 1 year ago

Please try v2.10.0 - https://github.com/RogerSelwyn/Home_Assistant_SkyQ_MediaPlayer/releases/tag/v2.10.0

This required HA 2022.10. Also Sky Q must be set up via UI and "Get Live Record status" must be enabled

Locoblade commented 1 year ago

Roger, brilliant work and amazing turnaround, thank you! I'm liking it also shows what program is scheduled to be recorded, really nice.

friendly_name: Sky Q Living Room Schedule skyq_scheduled_start: 2022-10-25T19:00:00 skyq_scheduled_end: 2022-10-25T20:15:00 skyq_scheduled_title: New: The Great British Bake Off

I already smart switch control our Sky Q Minis overnight to save power as they also use almost 10w each in standby, with this I can now shut down the main Q box as well. 20w doesn't sound a lot but running constantly it's £5 a month in electricity at UK current standard tariffs, and more like £15 with 4 Minis running constantly as well.

RogerSelwyn commented 1 year ago

I am doing something similar but cruder for a Sky box at a holiday let, just switch it (and tv/dvd) off when no-one is there. About 40w total during the day, 20w over night.

Locoblade commented 1 year ago

I'll find out in a bit but what happens during a scheduled record, does it update with the next schedule times at the start of the recording or at the end?

RogerSelwyn commented 1 year ago

It shows currently recordings in the recordings attribute (which is an array not shown in your example), the attributes you show give the next scheduled recording. Bear in mind you may be recording multiple items at the same time.

https://rogerselwyn.github.io/Home_Assistant_SkyQ_MediaPlayer/schedule_sensor.html

Locoblade commented 1 year ago

The above I quoted are the only attributes I'm seeing under the schedule sensor entity, do I need to configure something else to get that additional info? Edit - ah that only appears when it's actually recording

Locoblade commented 1 year ago

Hi Roger, would it be possible to add something like an "is_recording" true/false attribute or even change the sensor state to "Recording" rather than "Scheduled" when a recording is in progress to allow a bog standard state/attribute condition within an automation etc to easily determine if the box is recording something or not?

I can query "recordings" using this {{state_attr('sensor.sky_q_living_room_schedule', 'recordings')}} which gives an output of the recordings array or "NULL" if there's no recording(s) in progress but being an attribute array and one that doesn't always exist it doesn't appear to be straightforward (for me anyway!) to use that information as a condition to ensure my automation doesn't shut the device down during a recording.

Thanks

RogerSelwyn commented 1 year ago

All you need to do is check for the existence of that attribute, if it is present it is recording, if it isn't present, it isn't recording. You don't really need to process the array, but I thought the info might be useful to someone.

Comparing the attribute to None should do the job, which will check to see if it exists or not.

RogerSelwyn commented 1 year ago

Bear in mind all times in there are UTC not local time.

Locoblade commented 1 year ago

All you need to do is check for the existence of that attribute, if it is present it is recording, if it isn't present, it isn't recording. You don't really need to process the array, but I thought the info might be useful to someone.

Comparing the attribute to None should do the job, which will check to see if it exists or not.

Thanks Roger, it took a bit of head scratching as I generally have to do a lot of Googling to get templates etc written correctly but a template condition using the following which (may be useful for others) appears to do the job.

{{state_attr('sensor.sky_q_living_room_schedule', 'recordings') is none}}

I also created a sensor to determine the number of minutes until the next recording so my power down automation will leave it on if a recording is about to start and also my power up automation can power it back on 10 minutes before the recording starts.

minutes_next_sky_recording: friendly_name: "Minutes until Next Sky Q Recording Starts" unit_of_measurement: "m" value_template: >- {{((state_attr('sensor.sky_q_living_room_schedule', 'skyq_scheduled_start')|as_timestamp|int - now()|as_timestamp|int)/60)|int}}

RogerSelwyn commented 1 year ago

Bear in mind that sensor may error if there is no scheduled recording (and I'd better check I have dealt with what happens if there is no scheduled recording).

You can use if/else statements in there.

I do use template sensors, but to be honest I use Node Red for all my automation because I can't be do with yaml based nature of ha automation. Too complex. Node Red lets me do far more complex things in a very visual way.

If you look on my GitHub you will find various repositories that show my Hassio config, which may give some clues for templates.

Locoblade commented 1 year ago

Thanks, we've always got several series links scheduled so its probably OK for my needs as-is but yep should follow best practice and make it accommodate situations like that.

I must get into Node Red, I did install it when I first installed HA but it confused me at the time and I've never gone back to it. I'll have a look at your repos, cheers

RogerSelwyn commented 1 year ago

Feature added with - https://github.com/RogerSelwyn/Home_Assistant_SkyQ_MediaPlayer/releases/tag/v2.10.0