[SOLVED] [Advice Needed] Announcement Rule

In my kitchen I have a Motion sensor, Hue light strip, Illumination Sensor and a Sonos Play:1. All of which are controlled or controllable from OH.

Generally I’m first up each day and head off to work about the time my wife comes down stairs. When the Kitchen motion sensor is activated the light level is checked and if below a certain value the Hue light strip is switched on. The Sonos then makes an announcement for me, giving me the current weather conditions, estimated time to get to work and other reminders I setup. This works quite well, about from the times when my wife decides to get up earlier than me, but that’s not to much of a concern.

I use a variable to keep track of the number of announcements that have been made.

When my wife comes downstairs, after I have gone to work. She should hear a full weather forecast and on certain days how long it will take her to get to the medical centre where she works.

So in the perfect scenario it all works well to a degree. This is where I’m hoping someone has a similar use case. My wife usually gets down stairs after 7:30 in the morning, is there a way of checking the current time and to only trigger a rule if it’s greater than 7:30?

This is what I’ve tried so far. But this doesn’t seem to work as I would have expected.

if(now.getHourOfDay > 6) {
if(now.getMinuteOfDay > 30) {

Thanks in advance for your help and assistance. I’m hoping this is a problem that has already been solved.

Hi

I do something similar, but different.

We have a ChromeCast Audio in our bathroom, when we have a shower the water flow temperature triggers the ChromeCast to stream our choice of music.

However, our lodger sometimes takes a shower late at night, so we don’t really want the music playing.

After much head scratching, I decided the best way for me to proceed was to have a State I could refer to in rules to determine if music should be played. (as well as other things around the house, like the doorbell)

As I have a Velbus system, I have one of the spare virtual relays toggle state at our Wake Up and Bed Times.

So in a rule, it’s easy enough for something to trigger a rule, then perform actions based on the state of the “house awake” Item.

var String  musicurl = {Our choice of music}

rule "play music"
when
Channel "velbus:vmb7in:abcdef012:07" triggered PRESSED
then

if (HouseAwake.state == ON) {
playStream("bathroom:chromecast:audio:123456789",musicurl)
}
else {
say("What are you doing having a shower at this time of day","bathroom:chromecast:audio:123456789") // It doesn't really say this, but there are times when I wish it did
}
end

If I were to do this purely within openHAB, I’d setup two cron triggered rules to set the state of a HouseAwake switch item.

I use this tool, but apparently there are better ways to format Cron Triggers. cronmaker.com

I guess you could expand it to reference 7 switch items so that you can easily change working day schedules, but that’s getting into scheduling which is a subject that is well documented :wink:

Using your approach with now.getHourofDay

You could look into getting the time of day in Minutes since midnight and devising a rule condition?

if (MinutesPastMidnight > 450){ //do stuff
}

Does that help you?

Update

Does this help?

or something like this…

(My coding skills are pants, so someone else will have to chip in on better ways to achieve this)

var Number MinutesPastMidnight = (now.getHourOfDay * 60) + now.getMinuteOfDay

if (MinutesPastMidnight > 450) { if (MinutesPastMidnight < 1200) {
    // do stuff
}}

Alternatively

You could use some kind of bluetooth beaconing to see who’s phone / device is in the kitchen?

in here Design Pattern: Time Of Day
in the first post rlkoshak uses
image

Hi Dario,

I’m already using Time of Day DP, which doesn’t help me with the problem I’m trying to solve.

Cheers,

Garry

Thanks Stuart,

You’ve given me some ideas to look at.

Cheers,

Garry

1 Like