You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
I've been playing around with Home Assistant a bit just to be familiar with the broader ecosystem, and one thing I'm somewhat jealous of is how easy it is to declare a calculated entity. OpenHAB can do some simple calculations (SUM, AVG) with groups, but not more complex, arbitrary calculations. It's relatively simple to do with rules, but I'd like to be even simpler. I'm thinking:
rule "#{target_item.name} Calculation" do
changed dependencies
run do
unless dependencies.all?(&:state?)
target_item.update(NULL)
next
end
target_item.update(block.call)
end
end
It'd be even cooler if we could automatically figure out the dependencies from the block, but that's likely hard even in the simple case, and not possible if the block calls other methods.
The text was updated successfully, but these errors were encountered:
Except that that's not the same thing. Passing items directly to only_if will call truthy? on them, not check if they have a state. For several things it's equivalent, but notably a SwitchItem will confuse things. For example:
If it were to use only_if, the final item would be NULL when it should be from room 2.
In general I dislike only_if and otherwise anyway. They only seem to serve as (confusing) syntactic sugar for core language constructs that already exist. They might save a level of nesting, but that can usually be ameliorated by using a guard clause anyway.
I've been playing around with Home Assistant a bit just to be familiar with the broader ecosystem, and one thing I'm somewhat jealous of is how easy it is to declare a calculated entity. OpenHAB can do some simple calculations (SUM, AVG) with groups, but not more complex, arbitrary calculations. It's relatively simple to do with rules, but I'd like to be even simpler. I'm thinking:
which would translate to
It'd be even cooler if we could automatically figure out the dependencies from the block, but that's likely hard even in the simple case, and not possible if the block calls other methods.
The text was updated successfully, but these errors were encountered: