Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zhimi.heater.na1 fails on discover climate entity #122

Closed
blakadder opened this issue May 6, 2021 · 18 comments
Closed

zhimi.heater.na1 fails on discover climate entity #122

blakadder opened this issue May 6, 2021 · 18 comments
Labels
enhancement New feature or request

Comments

@blakadder
Copy link
Contributor

Having issues adding zhimi.heater.na1

Climate entity throws two types of error.

Child Lock and Indicator light are discovered once enabled in Configuration.

Still missing the "Return to home" (urn:zhimi-spec:property:return-to-middle:00000003:zhimi-na1:1) and sound control (urn:miot-spec-v2:service:alarm:00007804:zhimi-na1:1) toggles

2021-05-06 18:00:41 ERROR (MainThread) [custom_components.xiaomi_miot_raw.climate] Modes {'Fan not swing': 0, 'Fan swing': 1} contains unsupported ones. Please report this message to the developer.
2021-05-06 18:00:41 ERROR (MainThread) [homeassistant.components.climate] Error adding entities for domain climate with platform xiaomi_miot_raw
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 376, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 485, in _async_add_entity
    capabilities=entity.capability_attributes,
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 192, in capability_attributes
    self.hass, self.min_temp, self.temperature_unit, self.precision
  File "/config/custom_components/xiaomi_miot_raw/climate.py", line 179, in min_temp
    return self._ctrl_params['target_temperature']['value_range'][0]
KeyError: 'target_temperature'
2021-05-06 18:00:41 ERROR (MainThread) [homeassistant.components.climate] Error while setting up xiaomi_miot_raw platform for climate
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 251, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 376, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 485, in _async_add_entity
    capabilities=entity.capability_attributes,
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 192, in capability_attributes
    self.hass, self.min_temp, self.temperature_unit, self.precision
  File "/config/custom_components/xiaomi_miot_raw/climate.py", line 179, in min_temp
    return self._ctrl_params['target_temperature']['value_range'][0]
KeyError: 'target_temperature'
@ha0y ha0y added the enhancement New feature or request label May 6, 2021
ha0y added a commit that referenced this issue May 7, 2021
@ha0y
Copy link
Owner

ha0y commented May 7, 2021

Do you mean zhimi.heater.na1 in your title?
This device is special - it totally violates the MIoT-Spec. So I just treat it as a special device. Try the latest commit, delete your device and add it again.

@blakadder
Copy link
Contributor Author

still throws an error:


2021-05-07 16:58:22 ERROR (MainThread) [custom_components.xiaomi_miot_raw.climate] Modes {'Fan not swing': 0, 'Fan swing': 1} contains unsupported ones. Please report this message to the developer.
2021-05-07 16:58:22 ERROR (MainThread) [homeassistant.components.climate] Error adding entities for domain climate with platform xiaomi_miot_raw
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 376, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 485, in _async_add_entity
    capabilities=entity.capability_attributes,
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 192, in capability_attributes
    self.hass, self.min_temp, self.temperature_unit, self.precision
  File "/config/custom_components/xiaomi_miot_raw/climate.py", line 179, in min_temp
    return self._ctrl_params['target_temperature']['value_range'][0]
KeyError: 'target_temperature'
2021-05-07 16:58:22 ERROR (MainThread) [homeassistant.components.climate] Error while setting up xiaomi_miot_raw platform for climate
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 251, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 376, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 485, in _async_add_entity
    capabilities=entity.capability_attributes,
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 192, in capability_attributes
    self.hass, self.min_temp, self.temperature_unit, self.precision
  File "/config/custom_components/xiaomi_miot_raw/climate.py", line 179, in min_temp
    return self._ctrl_params['target_temperature']['value_range'][0]
KeyError: 'target_temperature'

This is what's discovered in HA
image

@ha0y
Copy link
Owner

ha0y commented May 7, 2021

The exception stack trace you provided doesn't match the latest code. Perhaps you didn't install the latest commit successfully. Try again.

@ha0y ha0y changed the title zhimi.fan.za4 fails on discover climate entity zhimi.heater.na1 fails on discover climate entity May 7, 2021
@blakadder
Copy link
Contributor Author

Sorry, did a cp to wrong folder

Seems to be discovered as a climate entity now. Any way to change from "preset" for fan swing/not swing to "swing mode"?

Also, can the climate entity supporr target temperature if using an external temperature sensor?

There are 2 more options on this device:

  • sound mute - urn:miot-spec-v2:service:alarm:00007804:zhimi-na1:1
  • fan return to center enable/disable - urn:zhimi-spec:property:return-to-middle:00000003:zhimi-na1:1

@ha0y
Copy link
Owner

ha0y commented May 7, 2021

The climate entity can support current temperature to use an external temperature sensor.
Just select option for it in integrations page, and enter the entity id of your external temperature sensor.

@blakadder
Copy link
Contributor Author

yes that part is working, i'm asking about being able to set target temperature for that climate entity so it uses HA logic to turn off the heater when it reaches desired temperature like this which is achieved using Generic Thermostat:

image

@ha0y
Copy link
Owner

ha0y commented May 7, 2021

Afaik, HA doesn't turn off the heater when it reaches desired temperature. What you said was achived by Generic Thermostat 's code. See these:
https://github.com/home-assistant/core/blob/80b05c39cc5d8645a8686fec9777c2d330b2f4d6/homeassistant/components/generic_thermostat/climate.py#L430-L493

@blakadder
Copy link
Contributor Author

blakadder commented May 7, 2021

Any climate entity would behave the same according to https://developers.home-assistant.io/docs/core/entity/climate/, it needs to have SUPPORT_TARGET_TEMPERATURE enabled.


I've been playing around a bit and ran into some more errors:

This happens when trying to turn on indicator_light.


2021-05-07 18:19:53 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140144049533760] 'switch_status'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 167, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1481, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1516, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 742, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 376, in async_handle_light_on_service
    await light.async_turn_on(**params)
  File "/config/custom_components/xiaomi_miot_raw/light.py", line 217, in async_turn_on
    parameters = [{**{'did': self._did_prefix + "switch_status", 'value': self._ctrl_params['switch_status']['power_on']},**(self._mapping['switch_status'])}]
KeyError: 'switch_status'

most likely because the indicator_light implementation in this device does not have switch_status and uses value 2 as off, while 1is low brightness and 0 is high brightness


When the device is in the input mapping part of the config flow it doesn't auto select lock and indicator_light anymore. If I don't choose them from the dropdown and tick the checkboxes they cannot be configured from the CONFIGURE options even though they're shown there

image

If I add "lock" in the mapping menu, then try to add both indicator and lock from CONFIGURE menu, only the lock entity is added


If I try to add the temperature sensor later in the CONFIG menu I get the following error:

2021-05-07 19:40:13 ERROR (MainThread) [homeassistant.components.climate] Platform xiaomi_miot_raw does not generate unique IDs. ID na1-50EC50937879 is already used by climate.na1_50ec50937879 - ignoring xiaomi_miot_raw.na1-50EC50937879

I figured out the mapping for additional features on the device and will make a PR

image

Thanks for making a lot of it customizable!

@ha0y
Copy link
Owner

ha0y commented May 8, 2021

Any climate entity would behave the same according to https://developers.home-assistant.io/docs/core/entity/climate/, it needs to have SUPPORT_TARGET_TEMPERATURE enabled.

I think you have misunderstood the document. Do you refer to that

if a device is set to heat, and the target temperature is already achieved, the device will not be actively heating anymore

? That means that the stop of heating was handled by the device and reported to hass, so hass will know that the device is in heating mode but it is stopping now.

@blakadder
Copy link
Contributor Author

I was referring to this function in generic thermostat. Might be wrong with my limited Python knowledge, but the same feature works in Generic Thermostat and MQTT Climate entity.

Something like that in miot_raw component should allow to set target temperature in the UI card even if the miot spec doesn't have target_temperature property and then control the device based on that setting.

ha0y added a commit that referenced this issue May 15, 2021
@ha0y
Copy link
Owner

ha0y commented May 15, 2021

This commit should fix the problem on indicator_light.

@ha0y
Copy link
Owner

ha0y commented May 15, 2021

Something like that in miot_raw component should allow to set target temperature in the UI card even if the miot spec doesn't have target_temperature property and then control the device based on that setting.

As you can see, the _async_control_heating method is implemented in components/generic_thermostat, instead of components/climate . So it is not a generic function for all climate entity.

If your device support setting it, you can set it directly; otherwise, you can implement it by automation.

@blakadder
Copy link
Contributor Author

Yes, thank you. It was clarified by HA developers that internal heating control is implemented if an integration needs it. I've resolved the problem by creating a template switch which is then used by generic thermostat.

@ha0y
Copy link
Owner

ha0y commented May 17, 2021

That's good. I've seen your comment in the issue of another integration. How did you know that integration?

@blakadder
Copy link
Contributor Author

I've searching for all the ways of integrating xiaomi devices in Home Assistant. I'm doing a lot of testing for my blog and compatibility websites

@ha0y
Copy link
Owner

ha0y commented May 17, 2021

That's amazing. This integration aims to integrate ALL xiaomi devices and make users get rid of all YAMLs. Maybe I should improve English document in case others can't find it.

@blakadder
Copy link
Contributor Author

While not an issue for me, having chinese as default in HACS and when adding a device in the integration will stop many users from using this component

@ha0y
Copy link
Owner

ha0y commented May 18, 2021

Many thanks for your kind and constructive feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants