My main problem with Home assistant is the automation language. It could be very powerful, but isn't.

I feel that if there was a way to introduce temporary state and force an expression as the value of a switch it could be great. I would love for something ASP/Datalog based.

Having a light that's just on if some expression is True and off if the expression is false is more difficult than it should be. The automations are not goal-based. But maybe in a decade the next project will do it that way.

You can try pyscript (https://github.com/custom-components/pyscript), which allows you to write automations in plain Python.

That's not AI/Logic programming though. Ideally I'd write a boolean formula and the system tries to make it true by adjusting the values it can adjust.

Say I want something like the light should be off it is dark and the window is open (bugs), but if the window is closed and it is dark, the light should be on.

    dark & window.open -> !light
    dark & !window.open -> light
Obviously, it can't close the window. But it can turn the light to make the formulas true.

If this were answer-set-based, the system could find multiple ways to make the formulas true (that's why I say goal-based) and act in a truly intelligent manner.

Edit: if it could close the window, it had a second way to make the formulas true. That would be nice as well, that the window closes when I turn on the light.

Edit 2: note that at daytime the formulas are always true, such that I can adjust the light and window as I like.

Edit 3: We could also rewrite this as

    dark -> (window.open != light)
And it is great that we could reason about our rules in that manner.
> And it is great that we could reason about our rules in that manner.

That's what I've been missing as well. Node-RED comes close, but is event based.

I've been thinking of implementing this kind of system. It has similar principles to functional languages or a reactive system like Mgmt[0]. But I foresee a few issues that would render potential simple formulae into complex ones. Things like keeping state on event based inputs (push-type wall switches), time based decisions and outputs that don't provide feedback on their current state.

If I ever find the time to get practical with the idea and work out these issues I might put it into a Show HN.

[0] https://github.com/purpleidea/mgmt