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.
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.
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
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”
when
Item LokaleZeit_DatumUndZeit received update
then
if((Item ChristophsEchoDot_NChsterTimer) < (now.plusSeconds(90))) sendCommand(A_Tageslicht , ON)
//if(true) sendCommand(A_Tageslicht , ON)
end
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 ChristophsEchoDot_NChsterTimer.state
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.
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.
rule “AlexaBoxen”
when
Item LokaleZeit_DatumUndZeit received update
then
logInfo("Rules", "LokaleZeit_DatumUndZeit received update: {}", newState)
if ((ChristophsEchoDot_NChsterTimer.state as DateTimeType).zonedDateTime.isBefore((new DateTimeType).zonedDateTime.plusSeconds(90))) {
A_Tageslicht.sendCommand(ON)
}
end
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…)
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.
//-----------------------------------------
//Wenn Echo Alarm ausgibt soll x ausgeführt werden
//Erkennen der AlarmTypen
//Timer
rule "Timer_Timer"
when
Item ChristophsEchoDot_NChsterTimer changed
then
createTimer(new DateTime(ChristophsEchoDot_NChsterTimer.state.toString)) [|
sendCommand(T_Alarm , ON)]
end
//Alarm
rule "Alarm_Timer"
when
Item ChristophsEchoDot_NChsterAlarm changed
then
createTimer(new DateTime(ChristophsEchoDot_NChsterAlarm.state.toString)) [|
sendCommand(T_Alarm , ON)]
end
//Erinnerung
rule "Reminder_Timer"
when
Item ChristophsEchoDot_NChsteErinnerung changed
then
createTimer(new DateTime(ChristophsEchoDot_NChsteErinnerung.state.toString)) [|
sendCommand(T_Alarm , ON)]
end
//Aktion
rule "Alarm_Aktion"
when
Item T_Alarm changed to ON
then
sendCommand(A_Boxen , ON)
sendCommand(A_Boxen_Kanal_AV6 , ON)
sendCommand(T_Alarm , OFF)
end
//----------------------------------------------------------------------------