Adding components, need an easier guide for a noob

Hi,

I have a ventilation system that came non-connected. It turned out I could override it using relays, and have made it possible to remote control it using a Raspberry Pi. It is done via ssh + a python script with a trivial API:
ventilation.py -m {1,2,3}, where the integer denotes
ventilation.py -s, gives the status, i.e. which mode it is in
ventilation.py -f, to trigger a fire place function that creates overpressure to lid the fireplace (for 15 minutes)

Having been able to make that script shows that I know some programming. But to be honest, making custom components seems a huge step up. I read the 101 but did not understand even where to begin. Is there an easier 101 somewhere? This should be a trivial platform(?) with 2 components, a switch and a fan?

1 Like

I would like to second this request. It does seem a huge step and looking at the source is very confusing as every project seems to do things a different way. I seem to be able to handle config and setup but the event system is confusing. I would like to see a simple example of a serial device that sends data to HA in the form of UNIT and STATE.

I found the best way to learn was to go into the home assistant GitHub repository and look at similar components to the ones I wanted to create, and adapt the code to suit my needs. Itā€™s a pretty steep learning curve for us newbies.

2 Likes

Iā€™m just getting into this myself. Iā€™ve used many programming specific scripting languages over the years, but never developed applications. Iā€™ve recently invested time into learning python properly, not just application specific functions. So I have experience with lists, dictionaries and custom functions, know about classes, but havenā€™t really used them and have no idea what @properties are.

Iā€™ll get there with digging in and messing around, but with my level of knowledge itā€™ll be a slog. Iā€™m sure once I figure it, itā€™ll be an aha/dur! Moment, but I think there could be another page for the more junior members who want to contribute.

Iā€™ll document my findings as I go. I can suggest doing it in a separate docker so you donā€™t mess up your ā€˜productionā€™ build. This seemed like the easiest way for me to have a dev environment that I canā€™t mess up anything else.

Thanks for all the good leads here! I will copy a ā€œdemoā€ fan and try to work my way from there. I have a lot of rusty experience in java and c/c++, but have no idea about the structure here. So I also invested in python books to learn things properly (Book: Learning python the hard way).

Also, thanks for the separate docker tip. All in all, I ended on docker because my server is running ubuntu 16.04, with a tad to old version of python. I am glad that happened, and would stay on docker even when I eventually bump my server to 18.04.

When I get some results, I will post them here :slight_smile:

1 Like

I got a course on Udemy on python, got about half way through before I felt like I had a good grasp and abandoned it to start making my own stuff at work.

Setup/docker wise, I started with dockers on UnRaid, then moved to a Debian vm still on UnRaid. Then moved to hassio on raspberry pi, thatā€™s brilliant, but when I moved over to MariaDB, influx and NodeRed, it fell to pieces.

Iā€™ve now settled on an intelNUC with Ubuntu headless, but everything is setup with dockers, docker-compose and Portainer. I couldnā€™t be happier with that setup. Just the single docker-compose file would be enough to get a new system up and running again in no time, as long as I snapshot the config directory.

Dev setup is on macOSX though, with the new docker app/thing.

Love your attitude. Some people on these forums expect things to be easy, but they forget that programming/development is actually a specialised profession in its self and is not something you can just learn by reading a short document.

1 Like

Hi all, Iā€™m on Linux Arch and have just written a component and binary_sensor module. I will be completely and I mean completely documenting this in the coming days. One thing that helped me was using Pycharm as my editor. Pycharm is great and allows one to debug and step through multithreaded applications such as HA.

BTW there are Raspberry Pi components already, can you not use one of those? Maybe Iā€™m not understanding the problem but it seems they would work.

Hi all, Iā€™ve started in on this and it would be great to get some feedback, is this useful to anyone, does it help?
I am willing to expand any section of this, just let me know.

I have only part of the component documented but I will keep filling it in over the coming days. Here is the link.

https://www.cowlug.org/#homeassistant

2 Likes

Added more to the docs, included component setup this time.

1 Like

Component portion finished, now on to the platform code.

1 Like

Hi!

Thanks for writing this up! I will have a look today and give you feedback! And I just downloaded pycharm.

On my end, here is my progress:

  • I made proof-of-concept based on the flexit climate controller
  • I used spur to trigger the remote script over ssh
  • I realized that I am going to run into issues when I want to poll sensor data with this method
  • I discovered MQTT, and realized that it is the way to go
  • I am now making a MQTT daemon to run on the HVAC side :slight_smile:

That being said, I am glad I went through this because I need to enable spot cleaning on my neato. It is very conveniently placed in the hallway right where I need to vacuum often. So I will use the skills I have gotten so far to expand the neato component to support spot cleaning.

1 Like

@laffez excellent! I have done a few updates to the neato component myself :slight_smile: if you need any help testing feel free to tag me in the PR. Should be doable to do spot cleaning I think. I personally have a Botvac D7.

Hi,

I have now read your guide. Thank you! It helped a lot, and especially it made me realize how litte I did understand in the first place. There are a few major revelations that I realize:

  1. I had misunderstood the roles of platform and components. In particular, it looked to me like the platform was initiating the components, but now it seems it is the opposite?
  2. In python one can pass pointers to functions.

The most complex topic to me (that I am now starting to grasp after reading your guide) is the events piece. One thing that might make the guide even more useful would be to make a figure explaining:

  • What is the responsibility of the component vs platform in this example. Why is a platform needed here? Could the components just communicate with the GW directly?
  • An example of 2 sensors, and how they are added to all the dicts and lists at the end. Sort of a debug out. I suspect that there is 1 platform object and multiple sensor-components.

Again, thanks. This really helped a lot!

I have updated the docs and it now includes a SWITCH platform as well. I will take a look at adding an event diagram, thank you for the input.

You mixed up the component and platform idea, there is one component and multiple platform pieces. This is evident in the new docs. https://www.cowlug.org/#homeassistant

@dshokouhi: I have a botvac connected. It seems only to support the basic-1 instruction set. The D7 looks awesome, and I might buy one for myself for Christmas if there is support for no-go-lines and multiple maps directly in automation.

I have now made a pull request at pybotvac adding support for spot cleaning:

I also added a new version of neato.py for home-assisnt that can be used if the pull request goes through for pybotvac. In the meantime, I have this workaround added to the end of my neato.py component.


    def clean_spot(self, **kwargs):
    """Run a spot cleaning starting from the base."""
    """ Workaround with manual json until pybotvac is updated"""
    json = {'reqId': "1",
            'cmd': "startCleaning",
            'params': {
                'category': 3,
                'mode': 1,
                'modifier': 1,
                'spotWidth': 400,
                'spotHeight': 400}
            }
    self.robot._message(json)

Sorry the other question you asked. From the developer docs https://developers.home-assistant.io/docs/en/creating_platform_code_review.html they specifically request not communicating directly with hardware. See point 6.

Not sure I agree this is a good idea or not but there it is.

1 Like

Hey all, I have added a bit more to the descriptions and also added an attempt at an event diagram.
Please comment if you like.

1 Like

Yeah, youā€™re not doing this to an empty auditorium. Iā€™ve been reading even if nobody else has, and I am definitely learning from it. I just donā€™t have enough hours in the day to try and have a dabble myself atm, hence me not saying anything :slight_smile:

Thanks for the guide. I am learning to program in my spare time and am very much a beginner, so reading through your tutorial helped with my understanding slightly, but still lost. Thatā€™s more on me than you, since Iā€™m missing gaps of knowledge and experience. I think the the toughest thing for me was understanding all the hass-specific objects and functions, but spending hours looking at other components has helped.

I have my custom component working right nowā€“next step is to create a Lovelace card but I have zero experience in javascript. Iā€™m amazed what people have written so far with so little Home Assistant documentation out there.