Xiaomi Gateway Integration

Ok, so the second gateway is not found by HA. Is it on the same network as the other gateway?

different WiFI, but same network

192.168.1.230 one
192.168.1.231 second

the Xiaomi app sees both

Thanks @Danielhiversen.
I’m trying to use it like that but I get:

17-01-31 21:30:07 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: expected int for dictionary value @ data[‘brightness’]. Got ‘{% set state = states.light.living_room.attributes.brightness + (trigger.event.data.action_value|float)/90 %} {{ state }}’

code:

- alias: Living room Cube rotate
  trigger:
    platform: event
    event_type: cube_action
    event_data:
      entity_id: binary_sensor.cube_158d0001035712
      action_type: rotate
  action:
    service: light.turn_on
    entity_id: light.living_room
    data:
      brightness: >
                  {% set state = states.light.living_room.attributes.brightness + (trigger.event.data.action_value|float)/90 %}
                  {{ state }}

It’'s like it’s just parsing the templates as string and not converting…
Also, do you know how can I debug (trigger.event.data.action_value|float)/90 to know the output value? I need to change it to go from min0-255max.

Thanks.

replace data with template_data, as in my example

Check my example to see how I made sure it was between 0 and 1.

I think the Xiaomi app gets the data via China. :smile:

So try to connect them to the same wifi. I think this is a network issue

他媽的 :smile:

man I need the second gateway to be on that WiFi, because the gateway will be too far away from the other Wifi

Hope @rave can fix this

EDIT: let me see if connecting to the same Wifi works

Try to connect the gateway to the other wifi, to check if that works.
If that works, you know it is a network issue. Then you should try to check the settings on your router.

router is fine, I have around 200 devices on the network, split between the two WiFi, and all interact with each other

Is still think you should try to connect the gateway to the other wifi, to check if that works.

yes, like this it works …

Ok, so it is something wrong with the network settings. The Xiaomi component broadcast a package to discover all gateways, and for some reason the package never gets to the gateway on the other wifi.

Thanks, that was stupid of me…
Anyway, now I’m getting:

17-01-31 22:05:51 ERROR (Thread-12) [custom_components.light.yeelight] Error when calling <function YeelightLight.set_default at 0x6efebf18>: {‘message’: ‘general error’, ‘code’: -5000}

>   action:
>     service: light.turn_on
>     data_template:
>       entity_id: light.living_room
>       brightness: >
>                   {% set state = states.light.living_room.attributes.brightness + (trigger.event.data.action_value) -%}
>                   {%-  if state > 255 -%}
>                     {%- set state  = 255 -%}
>                   {%-  elif state < 0 -%}
>                     {%- set state  = 0 -%}
>                   {%- endif %}
>                   {{ state|round }}

Setting the brightness directly like this works fine:

  action:
    service: light.turn_on
    entity_id: light.living_room
    data:
      brightness: 255
1 Like

mmhhh, I have 2 WiFi

  1. WIFI-1st floor where I am now programming all
  2. WiFI–GroundFloor where the Gateway2 should go.

Now I connected the Gateway2 to the WIFIGroundfloor (but I am in first floor and that WiFi is weak).
Maybe putting it somewhere where is not weak will go, have to check

Go to YOUR_IP:8123/dev-template to test and validate the template.

Replace trigger.event.data.action_value with a test number.

I also think you need to convert the rotation to a float is I did, (trigger.event.data.action_value|float)

Testing through there seems fine. I’m using round at the end anyway so I always get an integer…

Ok, but I though the rotate value might be a string that needs to be converted to a number.
i do not know the yeelight component, so do not know what the error code mean.

YES! The problem was the weak WiFI.

Strangely during initialization of the Gateway the weak WiFi was enough to make iit connect and register to it.

But then in HASS was not strong enough … strange …

Great, so it works now?
One gateway connected to each network and both connected to HA?

1 Like

Yes one gateway to one wifi, and other gateway to other wifi. Both inside HASS working.

Thanks!!!