val Number Waschmaschine_MODE_OFF = 0
val Number Waschmaschine_MODE_STANDBY = 1
val Number Waschmaschine_MODE_ACTIVE = 2
val Number Waschmaschine_MODE_FINISHED = 3
val Number Waschmaschine_MODE_CREASE_PROTECTION = 4
var Number Waschmaschine_Counter = 0
//#########################################################################//
//Waschmaschine Status anhand des aktuellen Stromverbrauches setzen //
//Wenn Status Fertig, dann Telegram senden //
//#########################################################################//
rule "Waschmaschine Status"
when
Item Steckdose_Waschmaschine_Strom changed
then
logInfo("WaMa Strom Durchschnitt 30 min", Steckdose_Waschmaschine_Strom.averageSince(now.minusMinutes(30)).toString)
if (Steckdose_Waschmaschine_Strom.state < 1) Waschmaschine_OpState.postUpdate(Waschmaschine_MODE_OFF)
else if (Steckdose_Waschmaschine_Strom.state > 100 && Waschmaschine_OpState.state !== (Waschmaschine_MODE_CREASE_PROTECTION) || Steckdose_Waschmaschine_Strom.state > 500){
Waschmaschine_OpState.postUpdate(Waschmaschine_MODE_ACTIVE)
}
if (Waschmaschine_OpState.state == (Waschmaschine_MODE_ACTIVE) && Steckdose_Waschmaschine_Strom.state < 2){
Waschmaschine_Counter = Waschmaschine_Counter + 1
}
if (Steckdose_Waschmaschine_Strom.state > 1 && (Steckdose_Waschmaschine_Strom.averageSince(now.minusMinutes(2)) as Number) < 50) {
if (Waschmaschine_OpState.state == Waschmaschine_MODE_OFF) Waschmaschine_OpState.postUpdate(Waschmaschine_MODE_STANDBY)
}
if (Waschmaschine_Counter > 6){
if (Waschmaschine_OpState.state == Waschmaschine_MODE_ACTIVE){
Waschmaschine_Counter = 0
Waschmaschine_OpState.postUpdate(Waschmaschine_MODE_CREASE_PROTECTION)
}
}
if ((Steckdose_Waschmaschine_Strom.averageSince(now.minusMinutes(30)) as Number) < 150){
if (Waschmaschine_OpState.state == (Waschmaschine_MODE_CREASE_PROTECTION)) Waschmaschine_OpState.postUpdate(Waschmaschine_MODE_FINISHED)
}
end
Coming from a C# background, I have an expectation that invalid comparison operations will fail in at compile time most often, and maybe throw an exception at runtime under special cases. My troubleshooting in OH rules is usually complicated by the fact that everything just appears to work until you add a logInfo after every line!
Could you give me some guidance on the Number:Temperature type? I only came across this item type when I started using the Wunderground binding. Part of the problem is that I don’t really understand what types with colons really mean, and I can’t find any documentation about it. I presumed it’s like a subclass which simply overrides the the ToString() method (or whatever it’s called), but have found that comparisons to numbers always return false (without an exception) and casting to a Number (as Number) seems to have no effect. Consider this rule snippet:
var float _maxOutsideTemp = 23.0
...
if ((Weather_MaxTemp_0.state as Number) < _maxOutsideTemp)
{
logInfo("my.rules", "max temp (" + (Weather_MaxTemp_0.state as Number) + ") < " + _maxOutsideTemp)
}
This gives the non-intuitive result:
max temp (20 ℃) >= 23.0
That makes me wonder whether the left side of the comparison is being treated as string, but surely that should cause an exception or, ideally, a compilation error.
Is there an incantation to allow a useful comparison of a Number:Temperature item with a rule-defined variable? Comparison between two items of the Number:Temperature type seems to be OK.
That is not a valid expectation for weakly typed languages like the Rules DSL. There is no way for the compiler to have enough information to know if there will be an hour or not.
Unfortunately no I can’t. I’ve no experience with it and it is a new feature of OH 2.3. My understanding is that types like that allows one to set a flag somewhere to tell OH what units you prefer. Then it will automatically convert what ever the binding returns to your desired units.
Assuming I understand it correctly, you shouldn’t have to do anything special to use these items on your sitemap or rules.
I’m pretty positive it is far more involved than that.
They both implement Comparator so you wouldn’t get a compile time exception.
I suggest posting this as a new thread so more people see it. I can help unfortunately.
Am I right in saying I can use your conversion to convert the dimmer to a Number item? How would I then reference that new number state in a Widget? Do I create an item for it?
//to get state as Number
val dimVal = Zone_1_Volume.state as Number
if(dimVal > 50)...
val newDimVal = dimVal + 10
val int dimAsInt = dimVal.intValue
val float dimAsFloat = dimVal.floatValue
I don’t know anything about HABPanel so you might be better off posting a new thread in the HABpanel section of the forum.
That would be a requirement to convert a Dimmer item too a Number Item. Bed aware that the conversion code above is in Rules DSL, not JavaScript which is what HABPanel widgets after written in.
17:37:44.013 [WARN ] [.rest.core.internal.item.ItemResource] - Received HTTP POS T request at ‘items/Zone_1_Volume’ with an invalid status value ‘Decrease’.
but with Capitals it does kinda!
17:39:36.376 [INFO ] [smarthome.event.ItemStateChangedEvent] - Zone_1_Volume changed from 52 to 58
17:40:11.514 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Zone_1_Volume' received command DECREASE
17:40:11.533 [INFO ] [smarthome.event.ItemStateChangedEvent] - Zone_1_Volume changed from 64 to 60
17:40:12.201 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Zone_1_Volume' received command DECREASE
17:40:12.217 [INFO ] [smarthome.event.ItemStateChangedEvent] - Zone_1_Volume changed from 60 to 63
17:40:13.069 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Zone_1_Volume' received command DECREASE
17:40:13.086 [INFO ] [smarthome.event.ItemStateChangedEvent] - Zone_1_Volume changed from 63 to 59
17:40:13.828 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Zone_1_Volume' received command DECREASE
17:40:13.844 [INFO ] [smarthome.event.ItemStateChangedEvent] - Zone_1_Volume changed from 59 to 61
17:40:14.742 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Zone_1_Volume' received command DECREASE
17:40:14.760 [INFO ] [smarthome.event.ItemStateChangedEvent] - Zone_1_Volume changed from 61 to 58
I keep using DOWN in this scenario but it goes up a bit… lol!
EDIT: The AVR shows it going up and down fine, problem solved Thanks Vincent