New component which needs discovery, which example should i look at?

In case of HomeMatic it works by using callback functions. There’s the XML-RPC server which receives the messages of the HomeMatic hub, and my library has a way of passing functions to it which will be called as soon as a message arrives. In your case you would be running your own websocket-server that would receive the events. The component at the HASS side would then have update-functions that will be called so soon as your library receives the event. Kinda hard to explain. Your module would be some sort of man in the middle with a simple API hass would subscribe to.

@danielperna84 I see but is there an easy way to get this running now just in a simple way in my custom component before i get the hang of splitting things up like can i start this websocker in my component and make a method to call to ?

Also another question, i have this remote from IKEA which has 4 buttons and i’d like to get that into HASS. What kind of entity is that ? Is that a sensor ? binary_sensor ? The remote is zigbee and i get events in websocket when you click a button with a code so i can identify which button the user uses, there is no on of buttons just simple push buttons.

I have never done a custom component, so I’m not sure if there are any drawbacks to that approach. One that I would see is the async core HASS is using. It could be, that a component that somehow blocks while doing its work could mess up the rest of HASS. In your case you would need to start a websocket-server, which probably would be threaded when doing it the “easy” way. The HASS way would be to have an asynchronous serverm probably using the aiohttp module. Using async is a bit tricky though if you have never worked with it. But to wrap this up:
You custom component would need to:

  1. Start a websocket server which recives the messages
  2. Create entities according to what the “backend” says is available
  3. Tie the update-methods of your entities to the callback that’s handeling the websocket-messages

Regarding the IKEA: I have never used it, but depending on the implementation such devices with buttons don’t generate any entities. Instead only events on the HASS-eventbus are fired. You would see those if you set the log-level of HASS to debug. If you see something event- and device-related in the logs when pressing the buttons, then that’s how it has been implemented.

Thanks, so as i mentioned i used bloomsky component as inspiration and i copied as much as possible. I got the value from the temperature inside hass but only once. Its not getting updated. Does hass hass call the update by itself or do i need to do something ? When i have this running i will look into making a thread for the websocket then i guess i have to call update myslef and not rely on hass to call it. Brw i removed the throtteling from the bloomsky component just in case you were wondering. Maybe i should post some code but its so unstructured and ugly so i thought ill spare you that :wink:

Regarding the push button device. If it’s not an entity how i then use it in automations, how would i refer to it ?

I’m not up to date how HASS is doing this nowadays. Usually the update-method should be called once a minute or so. Maybe removing the throtteling disabled auto-updates. Not sure about that though.
Anyways, the easy way would indeed be to poll the states according to the update interval. That however would mean that it would take up to 60 seconds before HASS notices the change. That’s why going event-route would lead to much more accurate results.

The example for HomeMatic for automations based on events:

automation:
   trigger:
     platform: event
     event_type: homematic.keypress
     event_data:
       name: Kitchen Switch
       channel: 1
       param: PRESS_SHORT
   action:
     service: switch.turn_on
     entity_id: switch.Kitchen_Ambience

Other components have differnt event types and different even data. But in general that’s how event-based automations look like.

Hi @danielperna84, so i went the event way with an websocket and got it ALMOST to work. I have this issue: Event based Automation not working, why?. Maybe you have an idea ?

@donnib will the integration do push notifications? So the remotes will give instant events.

@Robban Yes, i made the first version of the component that supports Hue Motion Sensor, IKEA bulb (E14) and the 4 button remote. All work in HASS using Websockets. The remote gives instant response to HASS when you click on it using HASS events like @danielperna84 suggested albeit the code is VERY ugly and rough it works for the moment.

I like what I hear :+1:

Do you run deconz headless?

As soon as you get closer to release I will buy myself a conbee!

Well i don’t have a monitor connected to the rPi, it still run the ui app but i don’t use it. I just use the REST API and the Websocket to control and listen to events. I don’t know if i ever release the code as i am not sure it can reach prime time. There is a lot of work to make it nice i think. I am not even sure i will end up using it myself. I am a bit disappointed how zigbee devices work and the way the big companies implement it so if you want to make sure everything plays nice you have to use their own gateway sooooo… but then again none of the major companies, Osram, IKEA or Philips deliver a Websocket solution so polling is just plain stupid but i guess they are not quite interested their devices integrated with other things well.

I think Ikea Trådfri is actually pushing data, but I’d still prefer the internal hub.

If you’re not gonna finish the component, will you share it so someone else can pick it up and have a look and a try at getting it upstream? As I mentioned earlier, I am interested in getting this supported officially.

@Robban ok i didn’t know that.

Sure we will figure something out. I have not given up yet. I am implementing support for groups as we speak and expect to have it running during today.

Hi @donnib it would be great if you would share your component with us.
I’ve got the exact same idea / problem. My xiaomi motion sensors -> Deconz-> HA.
Polling them every x seconds does work but I don’t like it.
As a workaround I have created a node-red workflow. It listens on websocket events and sends those events trough MQTT to HA.

Your solution seems better to me, as it doesn’t needs node-red.

1 Like

Hi @donnib

I’ve ordered a conbee now and was thinking about writing a component, beginning with support for a couple of remotes to get stuff going. How is it going for you?

/R

@Robban Mine is what you can find above. I have not done anything more on it because deConz has been to unstable for me e.g not much use so i will continue when/if i solve the issues with my network until then there is not much motivation from my side especially because the custom module i wrote albeit being ugly it works for me and the unstableness is in the deConz. I have many ideas what i need to improve or how to refactor/rewrite the module but as i said i don’t have much motivation for this.

What is unstable about deconz?

well there many things i guess, for me specific is that i can’t use my light at all, sometimes they work which is rare and most of the times i can’t control them so…not much i can do. Manuel is trying to help and i am trying to provide information so we hopefully can nail it down. We are active discussing this here : https://github.com/dresden-elektronik/deconz-rest-plugin/issues/195#issuecomment-335476846 but there are other reports of issues like this or lights that disappear or freeze. Some could be deConz related and some might be because the manufacturers have implemented zigbee differently and only they know how to have a stable usage of the lights with their own gateway. It’s hard to tell.

That being said i am running beta because that is the only version with IKEA support so i am running on the edge but that is only way i have a chance of getting support for my IKEA lights which i have over 50 of.

That does indeed sound really tiresome…

What lights are you using? I’m mainly planning on using Philips hue and Ikea

I have 56 nodes where 3 are Philips (2 Philips dim switches and 1 motion sensor), 1 Osram gardenpole and the rest are IKEA lights/remotes. The majority are IKEA GU10 spots with a portion of E27 and few E14 lights.