Another component for ZiGate

Add light support (only brightness currently)

ok I try you component again.
Actually I have two switches completely recognized after second HA restart.
Remaining two others wall switches + wireless switch and ikea bulb are recognized but not created as switches and light.
Tried to reboot but now looks like I have issues with my SD card on my pi.
Maybe it did not like the debug mode.

Here’s one error I was able to see:

2018-07-04 20:08:42 ERROR (MainThread) [homeassistant.components.light] Error while setting up platform zigate
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 129, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.5/asyncio/tasks.py", line 400, in wait_for
    return fut.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/light/zigate.py", line 72, in setup_platform
    sync_attributes()
  File "/home/homeassistant/.homeassistant/custom_components/light/zigate.py", line 67, in sync_attributes
    entity = ZiGateLight(device, endpoint)
  File "/home/homeassistant/.homeassistant/custom_components/light/zigate.py", line 93, in __init__
    if action_type == zigate.ACTION_LEVEL:
NameError: name 'zigate' is not defined

Now I tried a fresh start by deleting the persistent file: /home/homeassistant/.homeassistant/zigate.json
After a restart nothing shown on my dashboard and only one device with no endpoint in config.
Second restart, I have two switches working again but not the same :smiley:
Looks like there’s 4 devices for a total of 8 switches but he stop after 4.
Light and wireless still not working.
persistent file : http://termbin.com/lck8
logs : http://termbin.com/oduh

working devices are :
addr: 409c endpoint: 2
addr: 84c3 endpoint: 1
addr: cef7 endpoint: 1
addr: cef7 endpoint: 2

Oops, my github was not up to date… that’s why light just failed, I’m sorry
I pushed the fix this morning, this will probably fix your wireless switch problem too

Deleting the persistent file is always a bad thing, some information can only be retrieve at pairing time or by asking a refresh and/or pushing the pairing button on XIAOMI devices to wakeup them.

Some missing entities could appear when their states change too, that’s why a completly unknown device could works because of the discovery system

Thanks again for testing.
Since I have no real bulb to test (not yet received) I didn’t see the mistake

Do you mean that you do not officially support devices that are already paired to the zigate when you start the component for the first time?

Devices already paired are supported, the system tries to discover their capabilities and then create according entities (sensor, switch, etc) but since devices running on battery sleep most of the time this discovery could not happen, because the device doesn’t answer. So the system will create entities only when the device talk to zigate.
For other device like bulbs, it’s not a problem because they are always listening so the discovery works.

At pairing time, device running on battery listen during few seconds so the discovery full works.

This discovery is called a refresh, you can call the service zigate.refresh_device to force a device refresh, you have to set the addr.
Example :

service : zigate.refresh_device
data:
  addr: ab01

Typically if you want to refresh a XIAOMI device running on battery you have to push the small pairing button one or more times just after calling the refresh in order to wakeup the device so it can answer to requests.

So it could explain my issue with wireless switch but not with the wall switch?
How can I try recover my four missing endpoints?

I think everything is ok now, but if you want to be sure, just wait a little I just received my OSRAM bulb :wink:

I’ve quickly setup a new hassbian install yesterday on a USB stick and now my ikea bulb is detected.
As you saied no on off state only brightness for the moment.
All my devices not on batteries are recognized I’ve only one of the wall switch were endpoint 2 was not listed. I was testing on my phone at that moment so I need to investigate deeper.
I also have notification for devices on battery which need to be refresh that’s great.
Thanks a lot for your work here.

I just made some adjustement this morning, now light works, supported features are onoff state, brightness and hue color

1 Like

Brightness works fine as before.
I can turn off light with the switch but the state in HA does not turn off.
After that only way to turn on is to change brightness.

Ok now I’ve my bulb, my four wall switches but the wirelless stil not show . (44a9)
Don’t know why I have e7d9
image
image

About the bulb problem, are you sure you use the last version from my git ?

About the Switch it’s strange, Can I have the persistent file zigate.json ?
You said it doesn’t show what do you mean? the binary sensor has been created

Yes I’ve clone your repository in custom_components.
Git pull says it’s up to date.
I had the exact same behavior with Elrich component and my switches before.
The light turns off and then report on to HA so HA reset the state to on even if switch was off.

Here’s my zigate.json: http://termbin.com/c5sw
Binary sensor is created, but no switch.
And strange there’s no zigate.44a9 entity.
Only zigate.e7d9 with addr attribute to 44a9 as shown in my capture before.

Maybe I’m wrong but I think it’s normal there’s no switch because you cannot drive it.
It’s different than wall switch.

To me, you can only push the button with your finger and get the information on the binary_sensor in Hass

Did you try to call the service zigate.refresh_device ? It could solve the bulb problem

Ok the refresh actually solve the bulb problem thanks.

I’ll try to use wireless switch with only binary.
But it’s not exactly what I expect. For example I would like to use it to turn off all lights, I can use automation for it and use the binary to trigger the automation, but I can’t display it as a switch in the dashboard I have to display the automation.

I’m not sure to understand what you want to do.
This device is a dual binary_sensor, you can only use it state .

A switch in home assistant means that you can control it, change the state from home assistant, like your wall switch.

If you want to use it to control different light from home assistant, you have to setup a automation and use the binary_sensor to trigger the automation, from on to off or off to on depending on what you want.

You cannot display a binary_sensor as a switch (but you can customize the device class to change appearance)
default appearance
image
or using light as device class
image

automation example :

automation:
  - id: '1528203166925'
    alias: test
    trigger:
    - entity_id: binary_sensor.zigate_ab01_onoff
      platform: state
      from: 'off'
      to: 'on'
    action:
    - service: persistent_notification.create
      data:
        message: "TEST"

If you want a virtual switch on the dashboard and trigger a automation, use an input_boolean

Ok I did not think about a virtual switch.
Using your code the automation works but not all the time.
See logs below but when it does no work I cant see any state change for the binary sensor.
Try quick and long push, does not solve the issue.

Not working:

2018-07-09 11:26:37 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state zigate.e7d9=2018-07-09 11:26:35; max_tx=100, friendly_name=44a9, missing=False, max_rx=100, manufacturer=1037, power_type=0, battery=2.995, type=lumi.sensor_86sw2, ieee=00158d0001f480c8, descriptor_capability=00000000, addr=44a9, bit_field=0100000000000010, max_buffer=127, icon=mdi:access-point, receiver_on_when_idle=False, battery_level=35, server_mask=0, last_seen=2018-07-09 11:26:35, mac_capability=10000000, rssi=159, rssi_percent=62, id=0 @ 2018-07-09T13:26:35.406126+02:00>, entity_id=zigate.e7d9, new_state=<state zigate.e7d9=2018-07-09 11:26:37; max_tx=100, friendly_name=44a9, missing=False, max_rx=100, manufacturer=1037, power_type=0, battery=2.995, type=lumi.sensor_86sw2, ieee=00158d0001f480c8, descriptor_capability=00000000, addr=44a9, bit_field=0100000000000010, max_buffer=127, icon=mdi:access-point, receiver_on_when_idle=False, battery_level=35, server_mask=0, last_seen=2018-07-09 11:26:37, mac_capability=10000000, rssi=159, rssi_percent=62, id=0 @ 2018-07-09T13:26:37.678747+02:00>>

working:

2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state binary_sensor.zigate_44a9_onoff=off; addr=44a9, attribute=0, friendly_name=zigate_44a9_onoff, endpoint=1, cluster=6 @ 2018-07-09T13:26:29.716390+02:00>, entity_id=binary_sensor.zigate_44a9_onoff, new_state=<state binary_sensor.zigate_44a9_onoff=on; addr=44a9, attribute=0, friendly_name=zigate_44a9_onoff, endpoint=1, cluster=6 @ 2018-07-09T13:27:29.049220+02:00>>
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state zigate.e7d9=2018-07-09 11:26:37; max_tx=100, friendly_name=44a9, missing=False, max_rx=100, manufacturer=1037, power_type=0, battery=2.995, type=lumi.sensor_86sw2, ieee=00158d0001f480c8, descriptor_capability=00000000, addr=44a9, bit_field=0100000000000010, max_buffer=127, icon=mdi:access-point, receiver_on_when_idle=False, battery_level=35, server_mask=0, last_seen=2018-07-09 11:26:37, mac_capability=10000000, rssi=159, rssi_percent=62, id=0 @ 2018-07-09T13:26:37.678747+02:00>, entity_id=zigate.e7d9, new_state=<state zigate.e7d9=2018-07-09 11:27:29; max_tx=100, friendly_name=44a9, missing=False, max_rx=100, manufacturer=1037, power_type=0, battery=2.995, type=lumi.sensor_86sw2, ieee=00158d0001f480c8, descriptor_capability=00000000, addr=44a9, bit_field=0100000000000010, max_buffer=127, icon=mdi:access-point, receiver_on_when_idle=False, battery_level=35, server_mask=0, last_seen=2018-07-09 11:27:29, mac_capability=10000000, rssi=198, rssi_percent=78, id=0 @ 2018-07-09T13:27:29.061787+02:00>>
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state binary_sensor.zigate_44a9_onoff=on; addr=44a9, attribute=0, friendly_name=zigate_44a9_onoff, endpoint=1, cluster=6 @ 2018-07-09T13:27:29.049220+02:00>, entity_id=binary_sensor.zigate_44a9_onoff, new_state=<state binary_sensor.zigate_44a9_onoff=off; addr=44a9, attribute=0, friendly_name=zigate_44a9_onoff, endpoint=1, cluster=6 @ 2018-07-09T13:27:29.074181+02:00>>
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.components.automation] Executing allumer gauche
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: name=allumer gauche, domain=automation, entity_id=automation.allumer_gauche, message=has been triggered>
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.helpers.script] Script allumer gauche: Running script
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.helpers.script] Script allumer gauche: Executing step call service
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=1975355152-296, domain=homeassistant, service=turn_on, service_data=entity_id=[‘light.tv’]>
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=1975355152-297, domain=light, service=turn_on, service_data=entity_id=[‘light.tv’]>
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1975355152-297>
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1975355152-296>
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.helpers.script] Script allumer gauche: Executing step call service
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=1975355152-298, domain=persistent_notification, service=create, service_data=message=TEST>
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, entity_id=persistent_notification.notification, new_state=<state persistent_notification.notification=notifying; message=TEST @ 2018-07-09T13:27:29.138093+02:00>>
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1975355152-298>
2018-07-09 11:27:29 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state automation.allumer_gauche=on; friendly_name=allumer gauche, last_triggered=2018-07-09T13:26:29.821565+02:00 @ 2018-07-09T13:22:28.516309+02:00>, entity_id=automation.allumer_gauche, new_state=<state automation.allumer_gauche=on; friendly_name=allumer gauche, last_triggered=2018-07-09T13:27:29.149381+02:00 @ 2018-07-09T13:22:28.516309+02:00>>

It could be interesting to set log level to debug for zigate too, so we can see who is eating the event

from configuration.yaml

logger:
  logs:
    zigate: debug

or calling service logger.set_level with data {“zigate”:“debug”}

About the entity_id zigate.e7d9 instead of 44a9, since there’s nothing wrong in the persistent file, could you check if you have done some customization to rename the entity_id ?
because there’s no reason to have such entity_id