Hacker News new | past | comments | ask | show | jobs | submit login

Pyscript adds rich Python scripting to HASS : https://github.com/custom-components/pyscript

An example script:

    @state_trigger("security.rear_motion == '1' or security.side_motion == '1'")
    @time_active("range(sunset - 20min, sunrise + 20min)")
    def motion_light_rear():
        """Turn on rear light for 5 minutes when there is motion and it's dark"""
        task.unique("motion_light_rear")
        log.info(f"triggered; turning on the light")
        if light.outside_rear != "on":
            light.turn_on(entity_id="light.outside_rear", brightness=255)
        task.sleep(300)
        light.turn_off(entity_id="light.outside_rear")
It's what made me ditch node red after going down the same path.



Can anyone comment on whether Pyscript vs AppDaemon is the better path? It felt like to me as someone that codes as a living PyScript was the better choice, but I also only ever used Python in college and grad school, and just haven't had the time to investigate a difference between the two and wanted to just get started. Using PyScript seems easy but it also feels like its just the main authors preferred way of working and is pretty buggy outside of how he likes to work in Jupyter notebooks

The Home Assistant community seems to have the entire gambit of people who can't code at all, the people who never coded professionally and make riduclously complex things like the fabled Excel accountants, to the professional developers doing stuff for fun, but nobody actually shares anything worthwhile outside of awful YAML and youtubes about awful YAML.


I'm currently using AppDaemon for a couple of webparsing-scripts. That has worked just fine without touching it for... well over a year by now.

But i have a nagging feeling that i should probably use PyScript instead.. If anyone has a more thorough analysis i'm open to hear it..


For what it's worth, I don't use the Jupyter notebooks. Just have a folder somewhere with python scripts that get reloaded as I edit them.


I've found that it just feels like I'm fighting a river to go up stream if I don't incorporate the web browser + Jupyter work flow that the author likes.

Auto complete for discovery just refuses to work in PyCharm and VSCode for me. The way PyScript is setup seems to be a strange bespoke system that kind of breaks the import system between files, type safety only sort of works sometimes, and just other quirks where I seem to just have to get used to all of the red underlines if I want to use an IDE as part of my development process.

But it still seems to be best option for allowing me to use any libraries in the ecosystem, gets rid of boilerplate, and the author is actively maintaining it. I didn't really find any other viable options outside of Python that would let me actually code my automations without yaml or a GUI.

I was very excited when I found a Kotlin implementation, KHome, but by the time I found it, it was already a seemingly dead project.


If you are expecting auto discovery of state variables or service calls then that would be nice, but that seems like a bit too much to ask. And it's not something that I personally feel is necessary as you're likely already are familiar enough with the home assistant states/services that you want to interact with by checking them out in the home assistant developer UI.

My PyCharm just shows those types as unknown, not as errors. I get auto completion & type checking for all the code I write myself.

It's also important to note that PyScript isn't regular python. Instead it's an interpreted script[1] that is compatible with the Python syntax. This is unfortunate, but enables most of the magic of PyScript which otherwise would not be practical.

[1] https://github.com/custom-components/pyscript/blob/master/cu...


The thing is, the Jupyter notebook does support auto discovery/complete of all of the state variables and services, but only in the browser. Not even in the notebook running inside the IDE.

It's just maddening that I can't seem to figure out how to get that one part working. I end up using a mix of the notebook and going through the developer UI, but wish I could figure out that one quirk.


Where is that stored? My beef with NodeRed was that it's not very git/manual-change/file friendly - random IDs and minor change in UI causing a large on-disk shuffle.

Even if I use a UI for making a modification sometimes, I want to be able to commit a clean diff like:

      sensorLightBackdoor:
    -   timeActive: range(sunset - 20min, sunrise + 20min)
    +   timeActive: range(sunset, sunrise)
Or whatever. Which obviously I can do with python, as long as it's stored neatly in config in a .py file, or even if embedded in HA yaml or something?


> Where is that stored

In a `pyscript/*.py` file, so you can open it with a full blown IDE and use all your usual comforts, and commit the results to git.


Awesome, thanks, this may be the push I needed back into HomeAssistant. :)


There's also NetDaemon for those who prefer C#: https://netdaemon.xyz/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: