Jump to content

New Plugin - Philips Hue Mood Lighting


BillOatman
Go to solution Solved by Prydwyn,

Recommended Posts

Bambu Utila
Just now, chef said:

Okay, I'll take a look at the code, but scenes should only run after 6:30pm.

That isn't happening?

Nope, sadly enough not.

I tied to start a movie and tv series after 6pm but before 12am and it doesn't work, after 12am also still doesn't work for me

Link to comment
Share on other sites

BillOatman
 return (DateTime.Now.TimeOfDay >= TimeSpan.Parse(profile.Schedule + ":00") && DateTime.Now.TimeOfDay <= TimeSpan.Parse("6:00:00"));

@chef

so configured time is 6:30pm

at 7pm DateTime.Now.TimeOfDay >= TimeSpan.Parse(profile.Schedule + ":00"  is true

but DateTime.Now.TimeOfDay <= TimeSpan.Parse("6:00:00") is false

and the logic is AND

You need to include the date component, not just the time

This is what I had using sunrise/sunset

        /// <summary>
        /// Check if it is currently daylight in the supplied location.
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <param name="offset">The offset (+/-) from sunset, in hours, to use to determine when to start setting light scenes.</param>
        /// <returns>True if during daylight hours, else false.</returns>
        public static bool isDaytime(double latitude, double longitude, int offset)
        {
            DateTime now = DateTime.Now.ToLocalTime();
            DateTime sunrise = GetSunrise(now, latitude, longitude);
            DateTime sunset = GetSunset(now, latitude, longitude);

         //   SimpleLog.Info("isDaytime: offset: " + offset.ToString() + "  sunrise: " + sunrise.TimeOfDay.ToString() + "   sunset: " + sunset.TimeOfDay.ToString() + "   sunset adjusted: " + sunset.AddHours(offset).TimeOfDay.ToString());

            if (now.TimeOfDay >= sunrise.TimeOfDay && now.TimeOfDay < sunset.AddHours(offset).TimeOfDay)
                return true;

            return false;
        }

So anything not daytime, the scenes were used.

Edited by BillOatman
  • Thanks 1
Link to comment
Share on other sites

BillOatman

Maybe that's what you do @chef

Define 2 times that give the range of when not to trigger scenes like sunrise and sunset and use the logic above but with your configured times.

DST becomes a nuisance, but it was already with your current configuration.

Edited by BillOatman
  • Like 1
Link to comment
Share on other sites

It took a moment but this seems to be it here:

        private static bool ScheduleAllowScene(PhillipsHueSceneEmbyProfile profile)
        {
            if (string.IsNullOrEmpty(profile.Schedule)) return true;
		
            return (DateTime.Now.TimeOfDay >= TimeSpan.Parse(profile.Schedule + ":00") || DateTime.Now.TimeOfDay <= TimeSpan.Parse("6:00:00"));
        }

Time is: 8:00pm = 20:00

Schedule Time is set: 7:00pm = 19:00

 

Time is greater then the scheduled time -> This is "true"

or

Time is less than 06:00 (6:00am) -> This is "false" (but condition is already "true").

 

at 24:00 (12:00am)  condition is already "true", is greater then 19:00

at 01:00 (1:00am) is greater then scheduled time (19:00) -> This is "false"... but is less then 06:00 -> This is  "true"

Both conditions on either side of the OR statement before 19:00 hrs will return "false", after 06:00 hrs.

 

 

 

 

 

 

 

Edited by chef
  • Like 1
Link to comment
Share on other sites

BillOatman
56 minutes ago, chef said:

It took a moment but this seems to be it here:


        private static bool ScheduleAllowScene(PhillipsHueSceneEmbyProfile profile)
        {
            if (string.IsNullOrEmpty(profile.Schedule)) return true;
		
            return (DateTime.Now.TimeOfDay >= TimeSpan.Parse(profile.Schedule + ":00") || DateTime.Now.TimeOfDay <= TimeSpan.Parse("6:00:00"));
        }

Time is: 8:00pm = 20:00

Schedule Time is set: 7:00pm = 19:00

 

Time is greater then the scheduled time -> This is "true"

or

Time is less than 06:00 (6:00am) -> This is "false" (but condition is already "true").

 

at 24:00 (12:00am)  condition is already "true", is greater then 19:00

at 01:00 (1:00am) is greater then scheduled time (19:00) -> This is "false"... but is less then 06:00 -> This is  "true"

Both conditions on either side of the OR statement before 19:00 hrs will return "false", after 06:00 hrs.

Heh, I usually see the simple solution first but not this time, well played :)

Link to comment
Share on other sites

Bambu Utila

YES! It's working!

I've downloaded the new version 1.1.0.1 and tried to start something before and after 12am, both are working as expected now!

Thanks you for fixing this!

Link to comment
Share on other sites

We could have also used De Morgan's Law, of Inversion ("!") to inverse the && (and) truth table to get the exact same outcome.

De Morgan's Law in Computer science says that by inverting an inverse && we get an || and vice versa, using the "bang" ("!").

"!(!bollean.value && ! boolean.value) == boolean.value || boolean.value"

Which is just Crazy right!

Edited by chef
  • Like 1
Link to comment
Share on other sites

On 8/24/2020 at 5:16 PM, NSBrad said:

Love the plugin.  It was exactly what I as looking for in Hue support.

I'm having an issue though where it randomly stops working.  I haven't found any pattern to it.  Last night it happened when a video I was watching ended and and when I hit play on the next episode it stayed in my stopped scene and didn't go to the playing scene.  I've had this happen to me a number of times over the last few months.  When it happens the configuration page doesn't list any of my scenes when I select any of the states in the configuration screen.  The only fix I've found so far is to reboot the server.  Are there any logs or anything that I can check or send in to try to figure out what's causing it?  I'm running the Emby server on a Synology NAS btw if that makes a difference.  

Is this issue not happening for anyone else?  I ran into it again last night.  

Link to comment
Share on other sites

BillOatman
On 9/18/2020 at 5:43 PM, NSBrad said:

Is this issue not happening for anyone else?  I ran into it again last night.  

@NSBrad  If your plugin config screen does not list any scenes that would imply that your Emby server cannot communicate with your hue hub. If it's a problem with the hub or the server is anyones guess, but if a server reboot corrects the situation, it would imply a server issue of some sort, either the server itself or Emby.  Maybe the Emby logs could shed some light on it.

Link to comment
Share on other sites

  • 4 weeks later...
marciodantas

 

On 3/6/2020 at 3:55 PM, BillOatman said:

If you go to the dashboard get the server log.  And make note in your post here the time you tried it.

Hey @BillOatman sorry to bump this, but here in my place we watch every movie through Chromecast. Would you mind taking a look at my server log and checking if you can enable Chromecast as a device in the plugin configuration? As @zackidack pointed before, it does show as an "active device" in dashboard even tough it's not shown as a "pickable" device in Hue plugin.

I started casting ~ 23:55

image.png.4a0057b998823e3a067a0835ecc4e21f.png

embyserver.txt

Link to comment
Share on other sites

BillOatman

@marciodantas The hue commands originate from the server not the client, so not the chromecast in your case.  There must be something wrong in the plugin configuration screen that isn't allowing the chromecast to be selected.,  @chef largely rewrote that code, but between he and I we should be able to figure it out.  But I do not have a chromecast device to test with and I do not know if @chef does or not.

Also is this a older chromecast or one of the new ones?

Edited by BillOatman
Link to comment
Share on other sites

Chromecast is a strange one. That device doesn't report playback. It is possible that the device which instantiated the playback to chromecast would trigger the event.

Link to comment
Share on other sites

BillOatman
1 minute ago, chef said:

Chromecast is a strange one. That device doesn't report playback. It is possible that the device which instantiated the playback to chromecast would trigger the event.

Yeah the older ones only operate when something "casts" to them.  The new ones are more like shields and run android tv.  Thats why I asked old or new chromecast.

@marciodantas  If it is a older chromecast is the device that is casting to it in the plugin list?

  • Like 1
Link to comment
Share on other sites

marciodantas

 

On 10/18/2020 at 1:22 PM, BillOatman said:

Yeah the older ones only operate when something "casts" to them.  The new ones are more like shields and run android tv.  Thats why I asked old or new chromecast.

@marciodantas  If it is a older chromecast is the device that is casting to it in the plugin list?

Yes guys, it's the old one (Chromecast Ultra) without the Google TV! 

 

@BillOatman yes all the device that is casting is in the plugin list. I tried with iPad (native emby app), S20 (Android 10) and through Chrome (OSX).. None of them worked... 

I'll try again later, but i'm thinking that chromecast makes the connection directly with the server, right? Doesn't seems to me that using the devices would trigger the plugin. 

On a side note, if you could enable a "Whatever device" in the list, that would defintely works for me! :)

Edited by marciodantas
Link to comment
Share on other sites

marciodantas

For any1 reading this thread...: 

On 10/19/2020 at 2:09 PM, marciodantas said:

 

Yes guys, it's the old one (Chromecast Ultra) without the Google TV! 

 

@BillOatman yes all the device that is casting is in the plugin list. I tried with iPad (native emby app), S20 (Android 10) and through Chrome (OSX).. None of them worked... 

I'll try again later, but i'm thinking that chromecast makes the connection directly with the server, right? Doesn't seems to me that using the devices would trigger the plugin. 

On a side note, if you could enable a "Whatever device" in the list, that would defintely works for me! :)

Ended up setting a script with ScripterX and ifttt and got it to work! thanks for the support guys!

Link to comment
Share on other sites

  • 5 weeks later...
altairr

Hi, 

First of all, thanks for the great plugin! It's been some time I've seen the plugin in the Catalog and finally made the switch to Hue recently.

I observed some weird behavior when I pause and un-pause a TV show or a movie. It's not happening all the time though.. When I pause the scene changes correctly. Sometimes however when I un-pause, the scene goes to unpaused and right after at the same second back to paused scene.

2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Reports Playback UnPaused...
2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Found Profile Device: SHIELD
2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Reports Episode will trigger Playback UnPaused Scene for SHIELD
2020-11-25 19:37:32.712 Info HttpClient: PUT http://192.168.1.230/api/yd7yxGuGVpPrazao7uVP0DAZ7Zlyq1sPZARtOZrr/groups/0/action
2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Reports Scene Trigger Success
2020-11-25 19:37:32.713 Info Server: http/1.1 Response 204 to 192.168.1.145. Time: 3ms. http://192.168.1.239:8096/emby/Sessions/Playing/Progress
2020-11-25 19:37:32.714 Info Phillips Hue: Phillips Hue Reports Playback Paused...
2020-11-25 19:37:32.714 Info Phillips Hue: Phillips Hue Found Session Device: SHIELD
2020-11-25 19:37:32.714 Info HttpClient: PUT http://192.168.1.230/api/yd7yxGuGVpPrazao7uVP0DAZ7Zlyq1sPZARtOZrr/groups/0/action
2020-11-25 19:37:32.716 Info Phillips Hue: Phillips Hue Reports Scene Trigger Success
2020-11-25 19:37:32.717 Info Server: http/1.1 Response 204 to 192.168.1.145. Time: 5ms. http://192.168.1.239:8096/emby/Sessions/Playing/Progress

I'm using 4.6.0.6 beta for the server and 1.8.54 (RC5) for Android TV on a Shield Pro. 

Thanks in advance for your help.

Link to comment
Share on other sites

BillOatman
On 11/25/2020 at 1:54 PM, altairr said:

Hi, 

First of all, thanks for the great plugin! It's been some time I've seen the plugin in the Catalog and finally made the switch to Hue recently.

I observed some weird behavior when I pause and un-pause a TV show or a movie. It's not happening all the time though.. When I pause the scene changes correctly. Sometimes however when I un-pause, the scene goes to unpaused and right after at the same second back to paused scene.

2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Reports Playback UnPaused...
2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Found Profile Device: SHIELD
2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Reports Episode will trigger Playback UnPaused Scene for SHIELD
2020-11-25 19:37:32.712 Info HttpClient: PUT http://192.168.1.230/api/yd7yxGuGVpPrazao7uVP0DAZ7Zlyq1sPZARtOZrr/groups/0/action
2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Reports Scene Trigger Success
2020-11-25 19:37:32.713 Info Server: http/1.1 Response 204 to 192.168.1.145. Time: 3ms. http://192.168.1.239:8096/emby/Sessions/Playing/Progress
2020-11-25 19:37:32.714 Info Phillips Hue: Phillips Hue Reports Playback Paused...
2020-11-25 19:37:32.714 Info Phillips Hue: Phillips Hue Found Session Device: SHIELD
2020-11-25 19:37:32.714 Info HttpClient: PUT http://192.168.1.230/api/yd7yxGuGVpPrazao7uVP0DAZ7Zlyq1sPZARtOZrr/groups/0/action
2020-11-25 19:37:32.716 Info Phillips Hue: Phillips Hue Reports Scene Trigger Success
2020-11-25 19:37:32.717 Info Server: http/1.1 Response 204 to 192.168.1.145. Time: 5ms. http://192.168.1.239:8096/emby/Sessions/Playing/Progress

I'm using 4.6.0.6 beta for the server and 1.8.54 (RC5) for Android TV on a Shield Pro. 

Thanks in advance for your help.

@Altair  When this happens the video does not pause?

@chef @Luke   This would appear to be a Emby bug, but also might explain things that I saw in the past that I attributed to the hue hub ignoring the command.  Not sure what the plugin could do except ignore commands within a second maybe.

Edited by BillOatman
Link to comment
Share on other sites

altairr
16 hours ago, BillOatman said:

When this happens the video does not pause?

No, when I unpause the video plays fine regardless of the scene. What I did as a workaround was to define a transition time of 500ms. There is still a strange thing happenning though. 
When I unpause a video, the scene switches rapidly and still has the one defined as Paused although the video is playing. After a couple of seconds the scene switches to the one defined as Unpaused. This doesn't happen every time, in some cases it goes directly to the Unpaused scene without the weird change. 

Link to comment
Share on other sites

On 11/25/2020 at 1:54 PM, altairr said:

Hi, 

First of all, thanks for the great plugin! It's been some time I've seen the plugin in the Catalog and finally made the switch to Hue recently.

I observed some weird behavior when I pause and un-pause a TV show or a movie. It's not happening all the time though.. When I pause the scene changes correctly. Sometimes however when I un-pause, the scene goes to unpaused and right after at the same second back to paused scene.

2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Reports Playback UnPaused...
2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Found Profile Device: SHIELD
2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Reports Episode will trigger Playback UnPaused Scene for SHIELD
2020-11-25 19:37:32.712 Info HttpClient: PUT http://192.168.1.230/api/yd7yxGuGVpPrazao7uVP0DAZ7Zlyq1sPZARtOZrr/groups/0/action
2020-11-25 19:37:32.712 Info Phillips Hue: Phillips Hue Reports Scene Trigger Success
2020-11-25 19:37:32.713 Info Server: http/1.1 Response 204 to 192.168.1.145. Time: 3ms. http://192.168.1.239:8096/emby/Sessions/Playing/Progress
2020-11-25 19:37:32.714 Info Phillips Hue: Phillips Hue Reports Playback Paused...
2020-11-25 19:37:32.714 Info Phillips Hue: Phillips Hue Found Session Device: SHIELD
2020-11-25 19:37:32.714 Info HttpClient: PUT http://192.168.1.230/api/yd7yxGuGVpPrazao7uVP0DAZ7Zlyq1sPZARtOZrr/groups/0/action
2020-11-25 19:37:32.716 Info Phillips Hue: Phillips Hue Reports Scene Trigger Success
2020-11-25 19:37:32.717 Info Server: http/1.1 Response 204 to 192.168.1.145. Time: 5ms. http://192.168.1.239:8096/emby/Sessions/Playing/Progress

I'm using 4.6.0.6 beta for the server and 1.8.54 (RC5) for Android TV on a Shield Pro. 

Thanks in advance for your help.

Seems like perhaps the Progress event is happening so fast we are unable to remove the paused scene from our persistent list before it is registering the unpaused action.

@BillOatman should we Task.Delay? 

Only side effect, is in some instances, the unpaused scene would seem sightly "laggy" compared to the rest. It would probably stop this behavior though.

Link to comment
Share on other sites

BillOatman
48 minutes ago, chef said:

Seems like perhaps the Progress event is happening so fast we are unable to remove the paused scene from our persistent list before it is registering the unpaused action.

@BillOatman should we Task.Delay? 

Only side effect, is in some instances, the unpaused scene would seem sightly "laggy" compared to the rest. It would probably stop this behavior though.

Delaying a second or 2 wouldn't be noticeable.  Particularly for those that use a ramp on the light level change. Worth a try I'd say.

  • Like 1
Link to comment
Share on other sites

57 minutes ago, BillOatman said:

Delaying a second or 2 wouldn't be noticeable.  Particularly for those that use a ramp on the light level change. Worth a try I'd say.

On it!

  • Like 1
Link to comment
Share on other sites

BillOatman

@chef  You might want to reverse the order here as well.

                    {
                        PlaybackUnPaused(e, config, config.SavedHueEmbyProfiles.FirstOrDefault(p => p.DeviceName.Equals(e.Session.DeviceName)));
                        PausedSessionsIds.RemoveAll(s => s.Equals(e.Session.Id));
                    }

 

Link to comment
Share on other sites

4 hours ago, BillOatman said:

@chef  You might want to reverse the order here as well.


                    {
                        PlaybackUnPaused(e, config, config.SavedHueEmbyProfiles.FirstOrDefault(p => p.DeviceName.Equals(e.Session.DeviceName)));
                        PausedSessionsIds.RemoveAll(s => s.Equals(e.Session.Id));
                    }

 

Yes this will also cut down on the amount of time it takes. Perfect! Nice catch!

Link to comment
Share on other sites

@altairr I'd love to know if the new version in the catalogue  fixes the issue.

The threshold of the delay can be customized, so if you find it still not meeting expectation, please mention it here in this thread.

 

1. Fixed un-paused session removal - order of operation to beginning of the method

2. Added Task Delay (150) //<- probably could be higher to compensate for altairr's 500ms.

 

 

Cool!

@BillOatman thank you sir! nice to know we're surviving 2020! blah!

Edited by chef
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...