Xiaomi smart home

Cheers… Note also changes motion sensors to proper binary_sensors so that’s awesome.

so i need to change all the configuration… because this part is no longer required if i understand…

binary_sensor:

  • platform: template
    sensors:
    corridoio:
    friendly_name: Corridoio
    value_template: “{{ states.sensor.magnet_xxxxxxxx.state == ‘open’ }}”
    sensor_class: opening
    entity_id:
    - sensor.magnet_xxxxxxxx

it’s correct?

@hangy Normally you only need to add one line to the configuration file:

aqara:

I made a mistake in the readme github sorry :blush:

Isn’t there a long press?

haha, thanks :grinning:
Nice the update you have make! Thanks for de work! For me too dificult…

Fooxy,

(Sorry for my englisch, i do my best :slight_smile:)

  1. The magnet is also working, displayed in the top as: magnet ** macadres ****
    In your discription you say use it as: sensor.magnet_SENSORID.
    But home assistant see the sensor as: binary_sensor.magnet_158d00010f7bb9

  2. In the manual: value_template: “{{ states.sensor.magnet_158d0001179ae9.state == ‘open’ }}”
    But HA displays on and off.

A wrong manual or a wrong .py file? :wink:
Again, Thanks for all your work, i love this :grinning:

Yes mistake too, I’ll fix it.
Thanks for the feedback.

@fooxy
Excellent. Sorry for the late reply. I am traveling these days.
It would be nice if we could also have the long press component/action (the switch has this option with the official app). Even better, if we could have triple click for actions that aren’t used that often (e.g. set a certain light color, reset something etc.).
I am expecting to see something new from Xiaomi since the price of the switches dropped significantly the last days.
Thanks again.
Regards.

I’m a bit confused by the app, as the current one is different from the images posted here, and I’m finding it hard to do anything with it, let alone enabling local communication. Are people using the latest linked android app or a previous one, and if so, where do I find it?

I had to use mainland china as the location to be able to add the products such as the motion sensor/magnet.

1 Like

Thanks accelle, using Mainland China did the trick.

i’ve modified the binary_sensor/aqara.py because magnet sensors status is on when the contact is closed (door closed)… but i think it’s more convenient the opposit so it became on when i open the doors.

the lines i’ve modified are: 44

if status =='close': change it to: if status =='open':

and line 88… same thing

if status =='close': change it to: if status =='open':

:slight_smile:

I used the “on” status when contact is close because it seems better for sensor badges.
I updated the code with your remark as it seems most logical.

@all,

I updated new version with a switch component.
I don’t have for the moment a switch for testing.
If some can test. thanks.

Nice, I’ve got a few switches.

Just tried on my test machine and the switches aren’t showing up? Unless I’m missing something.

have you updated the main aqara.py file at the root of the custom_components folder

1 Like

ok i’ve also the switch now i try your code… but the switch has 3 actions:

  • single click
  • double click
  • long click (long pressure on the switch)

if you need some debugging tell me how to do it (and sorry for my bad english but i’m italian) :wink:

16-12-21 21:56:04 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 335, in _async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 204, in async_add_entity
    yield from entity.async_update_ha_state()
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 220, in async_update_ha_state
    state = self.state
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 338, in state
    return STATE_ON if self.is_on else STATE_OFF
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 343, in is_on
    raise NotImplementedError()
NotImplementedError
16-12-21 21:56:04 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 335, in _async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 204, in async_add_entity
    yield from entity.async_update_ha_state()
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 220, in async_update_ha_state
    state = self.state
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 338, in state
    return STATE_ON if self.is_on else STATE_OFF
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 343, in is_on
    raise NotImplementedError()
NotImplementedError
16-12-21 21:56:04 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=group.all_switches, new_state=<state group.all_switches=unknown; order=16, entity_id=('switch.switch_double_click_158d0000f9b24e', 'switch.switch_one_click_158d0000f9b24e'), auto=True, hidden=True, friendly_name=all switches @ 2016-12-21T22:56:04.464119+01:00>, old_state=None>

Sorry being a Noob… How to add switch to Yaml?

Also getting this when starting 0.41

16-12-22 06:41:32 homeassistant.components.switch: Error while setting up platform aqara
Traceback (most recent call last):
File “/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py”, line 150, in _async_setup_platform
entity_platform.add_entities, discovery_info
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/debian/.homeassistant/custom_components/switch/aqara.py”, line 26, in setup_platform
sensorItems.append(AqaraSwitchSensor(gateway, device[‘sid’], device[‘sid’], device[‘model’],variable))
File “/home/debian/.homeassistant/custom_components/switch/aqara.py”, line 42, in init
self.deviceData = deviceData
NameError: name ‘deviceData’ is not defined

Im guessing just

Switch:
Platform: aqara

Also looking I think that error is just the value was left over cos I dont see that value being passed as a parameter to the method.

A lot of magnet switches I have seen have two options NC = Normally closed and NO = Normally open. Dont have one to check but might be an option within the Mihome app to swap them around?