The graph is a good indication that things are working. You can user the OH REST API to do some a queries against the db directly.
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.
Hi Rich,
I can see youve listed a Type conversion for a dimmer.
My current volume control of a thing is expressed as a Dimmer.
Items File:
Dimmer Zone_1_Volume "Volume [%.1f %%]" <soundvolume >
I am trying to create a Widget that does not use a Dimmer Type for Volume, Iām hoping to use commands to change the Volume like this:
<div class="widget" ng-class="{true: 'disabled'}[itemValue('Main_Zone_Power')=='PowerOff']">
<div class="icon off"><svg viewBox="0 0 48 48"><use xlink:href="/static/matrix-theme/squidink.svg#volume"></use></svg></div>
<div class="name">Volume<div class="value">{{itemValue('Zone_1_Volume')}}</div></div>
<div class="controlGroup">
<div class="control" ng-click="sendCmd('Zone_1_Volume', 'Up')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#top-arrow-2"></use></svg></div>
<div class="control" ng-click="sendCmd('Zone_1_Volume', 'Down')"><svg viewBox="0 0 80 80"><use xlink:href="/static/matrix-theme/squidink.svg#down-arrow-2"></use></svg></div>
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
New items file:
Number dimVal
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.
Hi Rich,
Forgetting habpanel, assuming a Basic UI sitemap how would I achieve this?
Just this piece of code? in a rule? im a little confused and new to OH2
Thanks
A DimmerType is a child of NumberType so you should be able to do all the same things to it.
Why donāt you reference the dimmer item directly? Does that not work?
If not then you will need another Number item and do this:
newNumber.postUpdate(Zone_1_Volume.state as Number)
@vzorglub HI Vincent, ill have already tried a direct reference to it with the sendCommand(Dimmer_Item, āUPā)
But I dont know what the dimmer item will respond to for the command. Ie, Up/Down, -/+ dont work.
A Dimmer item will accept the following commands (Number, Increase/Decrease, ON/OFF)
See:https://www.openhab.org/docs/configuration/items.html#type
Thank you Ill try Increase/Decrease before I look at the Type Conversion.
Just like the ON/OFF, itās INCREASE/DECREASEā¦ No quotes necessary in the rules. I donāt know about html stuff.
Doesnt work
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
Thanks for your DP threads - I almost always find a better way here than my existing ways of doing stuff.
HOwever, that does not work anymore:
The method getCalendar() from the type DateTimeType is deprecated
I just wanted to extract the hour of my DateTime Items (Sunrise / Sunset).
Thanks in advance
Thanks - got it:
val String rise = Weather_Sunrise_Time.state.format("%1$tH")
val Number hour_rise = Integer::parseInt(rise)