Zigbee2mqtt: getting rid of your proprietary Zigbee bridges (Xiaomi, Hue, TRADFRI)

- alias: Slaapkamer plafond aan 
  trigger:
    platform: mqtt
    topic: 'zigbee2mqtt/sensor.0x00158d00016bfc4b'
  condition:
    condition: template
    value_template: "{{ 'single' == trigger.payload_json.click }}"
  action:
    entity_id: light.mancave
    service: light.toggle

somebody knows why this isnt working?

Question: does this zigbee bridge supports communicating to which side a xiaomi cube was moved after a gesture? I would love to use a cube for setting an alarm where each side has a different time. Or use it to activate a scene.

This looks great. I’ve been looking at getting a few Xiaomi temp. sensors and door/window sensors. This looks to be better than the Xiaomi hub. I’ve ordered the parts as per the github repo, so hopefully they should arrive from AliExpress some time in the next 4 weeks and I can give this a go.

Dont use mqtt as the trigger.
Use the HA entity and the state transition from that.

Much easier.

Yes, it knows the ā€œfromā€ and ā€œtoā€ sides and posts them to MQTT for a ā€œflip90ā€. (For a ā€œflip180ā€ it only posts the ā€œtoā€ side, perhaps not unreasonably!)

Wow. Thats new never noticed that a week or so ago when I last checked… I am going to try and add mine to the system then and see what happens.

What issues are you having?

Could you give an example of such a configuration?

Try to use as topic: 'zigbee2mqtt/0x00158d00016bfc4b'. So without sensor.

  - alias: Slaapkamer plafond aan 
    trigger:
      platform: mqtt
      topic: 'zigbee2mqtt/0x00158d00016bfc4b'
    condition:
      condition: template
      value_template: "{{ 'single' == trigger.payload_json.click }}"
    action:
      entity_id: light.mancave
      service: light.toggle

As I said on the link - My errors are always: ā€œERROR Cannot get the Node Descriptor of the Device: 0x000d6f000b10d3db (Error: Timed out after 10000 ms)ā€ in spite of every effort to keep it awake.

Something like;

  - alias: 'Slaapkamer plafond aan'
    trigger:
      platform: state
      entity_id: sensor.0x00158d00016bfc4b
      to: 'on'
    action:
      entity_id: light.mancave
      service: light.toggle

It will depend on what ā€˜state’ the item gives in HA.
Look in the dev-state tab to see what it’s reporting.

If you want to use an attribute, it’s abit more code, but not too bad;

trigger:
    platform: template
    value_template: "{{ is_state_attr('sensor.0x00158d00016bfc4b', 'att_name', 'somevalue') }}"
  action:
    service: homeassistant.turn_off
    entity_id: light.lounge

This leaves you nice readable automations using the HA state changes, especially if you use the new feature in .75 to rename entityIDs

Hi everyone, got a query I’m stuck on with HA. I’m using the ā€œzigbee2mqttā€ HASSIO addon to use some Xiaomi Temp/Humidity sensors in the house. I can add them as sensors to display the temp/humidity fine, but I wanted to show the battery status on a tab to keep a track of them from an easy view. I have tried it using the sensor template method but couldn’t get it working. Anyone done the same or similar thing?
I have the below attributes available for the sensors:

sensor.0x00158d000187331d_temperature 22.89

battery: 95.00
voltage: 2985
unit_of_measurement: °C
friendly_name: Matilda Temperature
icon: mdi:temperature-celsius
hidden: false

Here are the settings I use for an occupancy sensor. Shouldn’t need much changing to use for a temp sensor (I think! :slight_smile: )

- platform: "mqtt"
  name: "Hall light sensor"
  state_topic: "zigbee2mqtt/occupancy1"
  availability_topic: "zigbee2mqtt/bridge/state"
  unit_of_measurement: "lx"
  icon: "mdi:theme-light-dark"
  value_template: "{{ value_json.illuminance }}"
  json_attributes: 
    - "battery"
    - "voltage"

- platform: template
  sensors:
    hall_light_sensor_battery:
      friendly_name: 'Hall light sensor battery'
      unit_of_measurement: "%" 
      value_template: '{{ state_attr("sensor.hall_light_sensor", "battery") | int }}'
      icon_template: >
        {% set battery_level = states.sensor.hall_light_sensor.attributes.battery | default(0) | int %}
        {% set battery_round = (battery_level / 10) |int * 10 %}
        {% if battery_round >= 100 %}
          mdi:battery
        {% elif battery_round > 0 %}
          mdi:battery-{{ battery_round }}
        {% else %}
          mdi:battery-alert
        {% endif %}

(Most of the battery stuff is to change the icon depending on the result.)

Thanks! Now I have to wait for my debugger :wink:

@PianSom cheers for the reply. What I don’t understand is how the mqtt sensor is linked to the template? What part of the template references the mqtt entry?

The first sensor ā€œhall_light_sensorā€ listens for the MQTT topic ā€œzigbee2mqtt/occupancy1ā€. The message is a json object, consisting of four fields - illuminance, occupancy, battery and voltage - and it sets the first to be its value and the other two to be son_attributes of itself (occupancy is handled elsewhere by a binary_sensor in this case). For example here’s a recent publication:

zigbee2mqtt/occupancy1 {"illuminance":166,"occupancy":true,"battery":"100.00","voltage":3035}

The second sensor ā€œhall_light_sensor_batteryā€ just grabs the ā€œbatteryā€ attribute of the first sensor as its value.

@PianSom sorry I’m getting myself confused. So from the logs for mine I see

2018-8-10 18:51:02 INFO MQTT publish, topic: ā€˜zigbee2mqtt/0x00158d0002009a7a’, payload: ā€˜{ā€œhumidityā€:52.09,ā€œtemperatureā€:24.63,ā€œbatteryā€:ā€œ100.00ā€,ā€œvoltageā€:3075}’

Then under my sensors I have
- platform: ā€œmqttā€
state_topic: ā€œzigbee2mqtt/0x00158d0002009a7aā€
availability_topic: ā€œzigbee2mqtt/bridge/stateā€
unit_of_measurement: ā€œ%ā€
icon: ā€œmdi:water-percentā€
value_template: ā€œ{{ value_json.humidity }}ā€
json_attributes:
- ā€œbatteryā€
- ā€œvoltageā€

  • platform: ā€œmqttā€
    state_topic: ā€œzigbee2mqtt/0x00158d0002009a7aā€
    availability_topic: ā€œzigbee2mqtt/bridge/stateā€
    unit_of_measurement: ā€œĀ°Cā€
    icon: ā€œmdi:temperature-celsiusā€
    value_template: ā€œ{{ value_json.temperature }}ā€
    json_attributes:
    • ā€œbatteryā€
    • ā€œvoltageā€

Do I need another sensor set up for the batter?

Please see the big blue box at the top of this (and every) page - make it easier for others to help you by posting your code in a readily readable fashion.

You don’t need to set up another sensor (or indeed the second), but it does make it a bit easier to see what is going on, I think. In your case it could be:

- platform: template
  sensors:
    my_battery_sensor:
      friendly_name: 'My battery sensor'
      unit_of_measurement: "%" 
      value_template: '{{ state_attr("sensor.XXX_the_name_of_your_first_sensor_XXX", "battery") | int }}'

Apologies, never had to put my config on before. Cheers I’ll give it a go!

I have done it in Lovelace as below…

  - type: entities
    title: Battery Status
    show_header_toggle: true
    entities:
      - sensor.front_bedroom_temp_battery
      - sensor.lounge_window_battery
      - sensor.3rd_bedroom_window_battery
      - sensor.back_door_battery
      - sensor.emmas_bedroom_temp_battery
      - sensor.3rd_bedroom_temp_battery
      - sensor.front_door_battery
      - sensor.motion_sensor_battery
      - sensor.presence_sensor_duncan_battery

Ooo I like this!! Cherrs guys