Rule: Start Action with Alexa Alarm

Hi, I have following situation:
An Echo Dot is connected to an external surround system from Yamaha.
When there is no Signal for 20min, the speaker will switch off.
Menes, when an alarm or an time rings I can not here it.

The script should switch on the speaker and change to the Input channel of the echo dot.

Al Items are working but I have now Idea how to create the rule.

I’m using already that Binding and I can see all values in the created thing :slight_smile:

That’s nice. Read that whole thread to see how to set up a rule from Alexa alarm time that sets up a timer to run at the given time.

I had read that, but the rule examples do not fit my situation. Is it not possible to compare two values in an If?


The command is working, when I use for example an switch, the test light switches on.

@ rossko57
Ok, I thought you meant the Link in the treat about the binding, now I had seen that there is in the top also the link to the topic.

Of course. Have you tried?

1 Like

Only with that both Date and Time values, But i can try it for example with two volume level values, there are not many Signals that are not just bool that i have in my OpenHab.

Well, I’m not writing it for you.

First, plan what you want to do.
That seems to be to run a rule every minute, and to see if the “alarm time” is past yet.
I think that is the wrong approach, but it will work.

So, create a rule that runs every minute.
Then find out how to use if() to compare “now” with a DateTime type item.
Remember not to see if it is equal - it never will be in milliseconds.
Test to see if now > alarm

Here’s a useful resource

There is the problem that the “Next Timer” Item gets an value of “-” when the alarm is ringing and there is no other timer.

Okay, what do you need to do about that?

The Idea that I had with that was to switch on the light before the alrm starts but there is still the problem with the comparison. The deactivated line works.

rule “AlexaBoxen”
Item LokaleZeit_DatumUndZeit received update
if((Item ChristophsEchoDot_NChsterTimer) < (now.plusSeconds(90))) sendCommand(A_Tageslicht , ON)
//if(true) sendCommand(A_Tageslicht , ON)

Please use code fences when posting code in this forum.

This is nonsense syntax.

You do not need the keyword Item outside of the ‘when’ trigger section.

ChristophsEchoDot_NChsterTimer is the whole Item object - with properties for label, group memberships, type etc. That cannot be compared with a datetime.
Usually you would be interested in its state property

The next problem you will come up against is that a DateTime type Item is not in the same format as the special variable now
This is explained in the DateTime conversion thread I pointed out.

Ok, Ill give up.
Main Problems:

  • Language barrier, I’m not a English person, so it’s hard to understand all the documentary.
  • I’m an PLC Programmer, in PLC Programming you are working very close with the Hardware, mostly direct with bit manipulation and there i can see all values during debugging in real time. I can see when I’m doing syntax errors. That is here not the case, I’m basically blind.

After nearly one night of reading different stuff I’m now just confused and give up. I understand you that you try to pull me in an specific direction but that does not help me, I have to find an example so that I can use this and edit the code for my use.
That night was just a waste of time.

In PLC Logic that is not an hard task, it’s strange that i should on in these language.

Try this, Christoph…

rule “AlexaBoxen”
    Item LokaleZeit_DatumUndZeit received update
    logInfo("Rules", "LokaleZeit_DatumUndZeit received update: {}", newState)
    if ((ChristophsEchoDot_NChsterTimer.state as DateTimeType).zonedDateTime.isBefore((new DateTimeType).zonedDateTime.plusSeconds(90))) {

Hi, thank you for that Code.
But it’s not working, where can I find the log what logInfo creates?

Either look in your /var/log/openhab2/openhab.log file or use log:tail in the console.

Understood. VSCode editor with openHAB extension is another thing to set up and learn - but gives you syntax checking. Saving much time in the end.

You know from PLC that it will never be done in one day.
Have another try when you are ready.

Good morning, after destructing my work of the last days because of stupidity ( I installed the new Pi in the housing of the old Pi and I had forgotten to put out the SD Card from the new Pi, which brake the card very easy in tow peaces…) :slight_smile:
Luckely I had done an save copy of all Databases and edited files to restore everything.

And this morning i woke up at 6:00am with an Idear which bacame the solution for me.

Very helpful for this was that Page from rossko57

Here my Solution:

//Wenn Echo Alarm ausgibt soll x ausgeführt werden

//Erkennen der AlarmTypen
rule "Timer_Timer"
        Item ChristophsEchoDot_NChsterTimer changed
       	createTimer(new DateTime(ChristophsEchoDot_NChsterTimer.state.toString)) [|
        sendCommand(T_Alarm , ON)]

rule "Alarm_Timer"
        Item ChristophsEchoDot_NChsterAlarm changed
       	createTimer(new DateTime(ChristophsEchoDot_NChsterAlarm.state.toString)) [|
        sendCommand(T_Alarm , ON)]

rule "Reminder_Timer"
        Item ChristophsEchoDot_NChsteErinnerung changed
       	createTimer(new DateTime(ChristophsEchoDot_NChsteErinnerung.state.toString)) [|
        sendCommand(T_Alarm , ON)]

rule "Alarm_Aktion"
        Item T_Alarm changed to ON
        sendCommand(A_Boxen , ON)
		sendCommand(A_Boxen_Kanal_AV6 , ON)
		sendCommand(T_Alarm , OFF)