Xiaomi Gateway Integration

If you have another Accesspoint, then change it for the Hub. Had the exact same error and after changing the Accesspoint everything worked.

As in, connect the hub to another access point?

Right. Somehow it has problems with specific Routers.

I can second this.
When I block the internet-access the door-window sensors go bonkers.
The switches are still working fine, so are the motion sensors.

Any idea how wo clarify this behaviour?

Hey mate, you need to make a group, and include all of the template sensors in that group, then it will show in its own card…

sensor: 
- platform: template
  sensors:
  - nursery_motion_battery:
      friendly_name: 'Nursery Motion Sensor'
      value_template: '{{ states.binary_sensor.motion_sensor_158d00010c2547.attributes.battery_level }}'
      icon_template: mdi:battery
      unit_of_measurement: "%"
  - entrance_motion_battery:
      friendly_name: 'Entrance Motion Sensor'
      value_template: '{{ states.binary_sensor.motion_sensor_158d0001535b8d.attributes.battery_level }}'
      icon_template: mdi:battery
      unit_of_measurement: "%"
  - front_door_motion_battery:
      friendly_name: 'Front Door Sensor'
      value_template: '{{ states.binary_sensor.door_window_sensor_158d000113061b.attributes.battery_level }}'
      icon_template: mdi:battery
      unit_of_measurement: "%"
  - temperature_sensor_battery:
      friendly_name: 'Kitchen Temperature Sensor'
      value_template: '{{ states.sensor.temperature_158d00011006a8.attributes.battery_level }}'
      icon_template: mdi:battery
      unit_of_measurement: "%"
  - studio_speaker_switch_battery:
      friendly_name: 'Studio Speaker Switch'
      value_template: '{{ states.binary_sensor.switch_158d00013f6fc3.attributes.battery_level }}'
      icon_template: mdi:battery
      unit_of_measurement: "%"

group:
- battery_level:
    name: Battery Level
    control: hidden
    entities:
    - sensor.nursery_motion_battery
    - sensor.entrance_motion_battery
    - sensor.front_door_motion_battery
    - sensor.temperature_sensor_battery
    - sensor.studio_speaker_switch_battery
2 Likes

Guys,

i’m try to add close \ open via the code

platform: template
sensors:
    front_door_status:
      value_template: '{% if states.binary_sensor.door_window_sensor_158d0001b %}
        {% if states.binary_sensor.door_window_sensor_158d0001b.state == "on" %}
          Open
        {% else %}
          Closed
        {% endif %}
        {% else %}
          n/a
        {% endif %}'
      friendly_name: 'Front Door'

i’m get a error how can i resolve it?

17-05-12 22:08:10 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [homeassistant]: [platform] is an invalid option for [homeassistant]. Check: homeassistant->customize->platform. (See /home/homeassistant/.homeassistant/configuration.yaml, line 1).

Thanks mate, it’s working like a charm!

I hope to find a way for see battery level on icons too, something like iOS battery monitor :smiley:

Thanks

    - platform: template
  sensors:
    kitchen_motion_battery:
      friendly_name: 'Кухня движение'
      unit_of_measurement: "%"
      value_template: >
          {%- if states.binary_sensor.motion_sensor_158d000128ca10.attributes.battery_level %}
              {{ states.binary_sensor.motion_sensor_158d000128ca10.attributes.battery_level|round }}
          {% else %}
              {{ states.binary_sensor.motion_sensor_158d000128ca10.state }}
          {%- endif %}
      icon_template: '{%- if  states.binary_sensor.motion_sensor_158d000128ca10.attributes.battery_level <= 5 %}mdi:battery-outline{%- elif states.binary_sensor.motion_sensor_158d000128ca10.attributes.battery_level >= 95 %}mdi:battery{% else %}mdi:battery-{{(states.binary_sensor.motion_sensor_158d000128ca10.attributes.battery_level|float / 10)|round*10}}{%- endif %}'
    room_motion_battery:
      friendly_name: 'Прихожая движение'
      unit_of_measurement: "%"
      value_template: >
          {%- if states.binary_sensor.motion_sensor_158d0001305fbf.attributes.battery_level %}
              {{ states.binary_sensor.motion_sensor_158d0001305fbf.attributes.battery_level|round }}
          {% else %}
              {{ states.binary_sensor.motion_sensor_158d0001305fbf.state }}
          {%- endif %}
      icon_template: '{%- if  states.binary_sensor.motion_sensor_158d0001305fbf.attributes.battery_level <= 5 %}mdi:battery-outline{%- elif states.binary_sensor.motion_sensor_158d0001305fbf.attributes.battery_level >= 95 %}mdi:battery{% else %}mdi:battery-{{(states.binary_sensor.motion_sensor_158d0001305fbf.attributes.battery_level|float / 10)|round*10}}{%- endif %}'
    bathroom_motion_battery:
      friendly_name: 'Ванная движения'
      unit_of_measurement: "%"
      value_template: >
          {%- if states.binary_sensor.motion_sensor_158d0001535c18.attributes.battery_level %}
              {{ states.binary_sensor.motion_sensor_158d0001535c18.attributes.battery_level|round }}
          {% else %}
              {{ states.binary_sensor.motion_sensor_158d0001535c18.state }}
          {%- endif %}
      icon_template: '{%- if  states.binary_sensor.motion_sensor_158d0001535c18.attributes.battery_level <= 5 %}mdi:battery-outline{%- elif states.binary_sensor.motion_sensor_158d0001535c18.attributes.battery_level >= 95 %}mdi:battery{% else %}mdi:battery-{{(states.binary_sensor.motion_sensor_158d0001535c18.attributes.battery_level|float / 10)|round*10}}{%- endif %}'

3 Likes

I like the dynamic icon statement!

icon_template: '{%- if states.binary_sensor.motion_sensor_158d0001305fbf.attributes.battery_level <= 5 %}mdi:battery-outline{%- elif states.binary_sensor.motion_sensor_158d0001305fbf.attributes.battery_level >= 95 %}mdi:battery{% else %}mdi:battery-{{(states.binary_sensor.motion_sensor_158d0001305fbf.attributes.battery_level|float / 10)|round*10}}{%- endif %}'

2 Likes

Similar to the battery level template sensor group, I’ve also set up a group to show me the current power usage of my plugs;

The only problem I have is that the the data only updates quite randomly, sometimes it will show the current power usage a few seconds after I turn the plug on, sometimes it won’t update for several minutes…

template sensor is made using code below;

studio_pc_power:
  entity_id: switch.plug_158d000153def1
  friendly_name: 'Studio PC'
  value_template: '{{ states.switch.plug_158d000153def1.attributes["Load power"] }}'
  icon_template: mdi:power-plug
  unit_of_measurement: "W"
2 Likes

Yes, when it just came out I did some debugging with @Lapatoc and it only updates on the heartbeat, approximately every 5 minutes.

No luck. I have an ASUS DSL-AC68U router and the AP - thought this was the problem. Now I added Fritzbox 7390 as another AP. I have the same issue.

It was the damn firewall! I had UFW running. Now its discovering the gateway, gets the IP etc, but bombs out further down.

This is the error i get now. Any help is appreciated.

So it can be used with standard bulbs like a relay?

Yes. The circuit is an ordinary switch / relay.

1 Like

Thanks mate I just make an order :smiley:

What’s the go with the L1 and L2 out?
One switch controls two devices?
If so is it only one on at a time?
What about with the double switch?

The single key version is equipped with one relay circuit. The double key wall switch has two relays (L1, L2).

As @syssi has said. L1 for switch 1, L2 for Switch 2.

If you’re unsure I really recommend you not play with these switches. Live electricity can kill you, get an electrician.

I got this working by changing a little bit of the python code in custom_components/xiaomi.py

I changed gateway_key to key in

def discover_gateways(self):
.
.
.
self.gateways[ip_add] = XiaomiGateway(ip_add, port, sid, key, self._socket)

Not sure if this is a bug, but works for me.