Xiaomi Gateway Integration

@pplucky It was past midnight when I was tinkering with it, so got a bit tired to feedback.

Yes I tried with all lower case

trigger:
  - platform: numeric_state
    entity_id: switch.plug_158dXXXXXXXXXX
    value_template: '{{ state.attributes.load_power }}'
    above: 3

(as well as putting a underline in front of load, just for fun…)

trigger:
  - platform: numeric_state
    entity_id: switch.plug_158dXXXXXXXXXX
    value_template: '{{ state.attributes._load_power }}'
    above: 3

No luck…but I was a bit tired yesterday, hopefully I will have time to make another try after work today.

This will work:

trigger:
  - platform: numeric_state
    entity_id: switch.plug_158dXXXXXXXXXX
    value_template: '{{ states.switch.plug_158dXXXXXXXXXX.attributes["Load power"] }}'
    above: 3
1 Like

maybe low capital L

I’m trying to create a template sensor for the load power and power consumed. I have two plugs, the template sensor is working for one but not the other and hass is giving me this error in the log:

2017-08-09 09:10:54 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 1782).

I have the same configuration for the two sensors, can’t understand why it’s not working.

can you post your code

The code it’s not the problem since it’s working with one of the power plugs, but here it is:

  • plataform: template
    sensors:
    monitor_power_usage:
    entity_id: switch.plug_158d00015e739f
    friendly_name: ‘Monitor Power Usage’
    value_template: ‘{{ states.switch.plug_158d00015e739f.attributes[“Load power”] }}’
    icon_template: mdi:power-plug
    unit_of_measurement: “W”

and for energy?

I have errors, what is wrong with this:

  - platform: template
    sensors:
      tv_power_usage:
        entity_id:  switch.plug_158d0001xxxxxx
        friendly_name: 'TV Power Usage’
        value_template: '{{ states.switch.plug_158d0001xxxxxx.attributes[“Load power”] }}'
        icon_template: mdi:power-plug
        unit_of_measurement: “W”
  - platform: template
    sensors:
      closet_power_usage:
        entity_id:  switch.plug_158d0001xxxxxx
        friendly_name: 'Closet Power Usage’
        value_template: '{{ states.switch.plug_158d0001xxxxxx.attributes[“Load power”] }}'
        icon_template: mdi:power-plug
        unit_of_measurement: “W”

For consumed power I have this:

  • platform: template
    sensors:
    fan_power_consumed:
    entity_id: switch.plug_158d000153de29
    friendly_name: ‘Fan Power Consumed’
    value_template: ‘{{ states.switch.plug_158d000153de29.attributes[“Power consumed”] }}’
    icon_template: mdi:power-plug
    unit_of_measurement: “W”

As i said, the code is working with one of the power plugs but not the other. And I get an error in the log, using the exact same code with different entity_id. The error only appears when I add the template sensor. Other than that the plug is working, but i can’t creat the template sensor for this plug, also HA doesn’t restart if the sensor is added to the config file.

I don’t think it changes the error. But Load is Power in W, Consumption is Energy and is Wh (or KWh)

It is an error, as I said both template sensors(load power and consumed power) are working with one of the plugs.
When I create the template sensor with the exact same configuration for the other plug I get this in HA logs:

2017-08-09 09:10:54 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 1782). Please check the docs at https://home-assistant.io/components/sensor/

And I don’t understand why I get this in the log: “required key not provided”

Please go to http://your-hass-instance:8124/dev-state and search for your “switch.plug” devices. Does both devices provide the attributes?

is my templating indentation wrong?

both are present and updated in the gateway app?

I do not understand what is wrong

  - platform: template
    sensors:
      counter_lights_on:
        unit_of_measurement: 'Lights'
        friendly_name: 'Lights on'
        entity_id:
          - switch.storageroom
          - switch.tvroom_wall
        value_template: >-
          {%- for item in states.group.all_lights_switches.attributes.entity_id  if states(item) == "on" %}
            {% if loop.last %}
              {{loop.index}}
            {% endif %}
          {% endfor %}
      tv_power_usage:
        entity_id:
          - switch.plug_158d0001530785
        friendly_name: 'TV Power Usage’
        value_template: '{{ states.switch.plug_158d0001530785.attributes[“Load power”] }}'
        icon_template: mdi:power-plug
        unit_of_measurement: “W”
      closet_power_usage:
        entity_id:  
          - switch.plug_158d000128c617
        friendly_name: 'Closet Power Usage’
        value_template: '{{ states.switch.plug_158d000128c617.attributes[“Load power”] }}'
        icon_template: mdi:power-plug
        unit_of_measurement: “W”

2017-08-09 13:07:07 ERROR (Thread-2) [homeassistant.util.yaml] while parsing a block mapping
in “/home/homeassistant/.homeassistant/sensor.yaml”, line 121, column 9
expected , but found ‘{’
in “/home/homeassistant/.homeassistant/sensor.yaml”, line 124, column 26
2017-08-09 13:07:07 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: while parsing a block mapping
in “/home/homeassistant/.homeassistant/sensor.yaml”, line 121, column 9
expected , but found ‘{’
in “/home/homeassistant/.homeassistant/sensor.yaml”, line 124, column 26

Yes, they’re both showing in the app and in dev state they’re both providing attributes and working. I don’t know if it makes any difference, but the plug that’s giving me the error was bought recently.

check if " and ’ character are the correct ones

Where? In [“Load power”] ?

Yes and other parts of the code

You have one gateway or 2?