Xiaomi Smart Space Heater S(zhimi.heater.mc2) plus zhimi.heater.zb1 (not tested) and zhimi.heater.za2 (not te

Thanks Sergio for the fast response.

1 Like

Hi.
Sorry if I’m being a n00b (just started in HA a few days ago) but I can’t make HA find the heater. I have a zb1, added your project by HACS and added this code to the configuration.yaml

climate:
  - platform: miheater
    host: 192.168.50.166
    token: !secret heater_token
    name: xiaomi_heater
    model: zhimi.heater.zb1

I’ve rebooted the server several times but I can’t find it in devices nor entities.

Does this requires a Xiaomi Gateway to work?

Hi!

You don’t need xiaomi gateway.
Have you already installed the integration?

Hi,
Yes, I have tryed installing by HACS and also manualy…
Both with same results, no device has been added

just rebooted the server to find this in the logs:

Logger: homeassistant.components.climate
Source: custom_components/miheater/climate.py:88
Integration: Climate (documentation, issues)
First occurred: 3:58:52 PM (1 occurrences)
Last logged: 3:58:52 PM

Error while setting up miheater platform for climate
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 199, in _async_setup_platform
await asyncio.shield(task)
File “/usr/local/lib/python3.8/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/miheater/climate.py”, line 88, in setup_platform
device = Device(host, token)
File “/usr/local/lib/python3.8/site-packages/miio/device.py”, line 121, in init
self._protocol = MiIOProtocol(ip, token, start_id, debug, lazy_discover)
File “/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py”, line 42, in init
self.token = bytes.fromhex(token)
ValueError: non-hexadecimal number found in fromhex() arg at position 33


Logger: homeassistant.components.climate
Source: components/climate/init.py:553
Integration: Climate (documentation, issues)
First occurred: 3:58:52 PM (1 occurrences)
Last logged: 3:58:52 PM

ClimateDevice is deprecated, modify MiHeater to extend ClimateEntity


Logger: homeassistant.loader
Source: loader.py:465
First occurred: 3:58:44 PM (2 occurrences)
Last logged: 3:58:45 PM

You are using a custom integration for miheater which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
You are using a custom integration for localtuya which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.

From the error it seems you are not using my code. I already have ClimateEntity not device.

Can you tell me from which repo you got the code?

Also, not everyone with you version of heater is able to make it work, but since it’s not my version, there is little I can test from my side :frowning:

Sorry, I believe I installed the version on HACS to test.
After deleting it and installing yours, only get this error:

Logger: homeassistant.bootstrap
Source: loader.py:541
First occurred: 4:35:47 PM (1 occurrences)
Last logged: 4:35:47 PM

Error setting up integration climate - received exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 64, in async_setup_component
    return await task  # type: ignore
  File "/usr/src/homeassistant/homeassistant/setup.py", line 174, in _async_setup_component
    processed_config = await conf_util.async_process_component_config(
  File "/usr/src/homeassistant/homeassistant/config.py", line 817, in async_process_component_config
    p_integration = await async_get_integration_with_requirements(hass, p_name)
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 47, in async_get_integration_with_requirements
    integration = await async_get_integration(hass, domain)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 481, in async_get_integration
    integration = Integration.resolve_legacy(hass, domain)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 259, in resolve_legacy
    comp = _load_file(hass, domain, _lookup_path(hass))
  File "/usr/src/homeassistant/homeassistant/loader.py", line 541, in _load_file
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 779, in exec_module
  File "<frozen importlib._bootstrap_external>", line 916, in get_code
  File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/miheater/__init__.py", line 7
    <!DOCTYPE html>
    ^
SyntaxError: invalid syntax

It seems it’s mixing several custom components. May I suggest you delete all miheater components you have and start over clean?

That error makes no sense with my code.

That is what I did. removed the install I had on hacs and made sure there was no other directory on the custom_components. Created the miheater folder and downloaded your files to that directory.

At the moment yours is the only component in the custom_components folder, and I get that same log message.

That is weird since I am not able to reproduce the error.
Can you confirm your version?

Also, I recommend to install my version using HACS by adding my repository.
And clean the cache please.

Removed everything, cleared cache, restarted browser, added by your HACS reporitory, restarted the server and:
´´´
Logger: homeassistant.components.climate
Source: custom_components/miheater/climate.py:67
Integration: Climate (documentation, issues)
First occurred: 9:07:56 PM (1 occurrences)
Last logged: 9:07:56 PM

Error while setting up miheater platform for climate

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 199, in _async_setup_platform await asyncio.shield(task)
File “/usr/local/lib/python3.8/concurrent/futures/thread.py”, line 57, in run result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/miheater/climate.py”, line 67, in setup_platform device = Device(host, token)
File “/usr/local/lib/python3.8/site-packages/miio/device.py”, line 119, in init self._protocol = MiIOProtocol(ip, token, start_id, debug, lazy_discover)
File “/usr/local/lib/python3.8/site-packages/miio/miioprotocol.py”, line 42, in init self.token = bytes.fromhex(token) ValueError: non-hexadecimal number found in fromhex() arg at position 33
´´´

This is really wierd… running your version 1.2 with Home Assistant 2020.12.1

I can see now that is seems to be complaining about your token.
Are you sure that is correct?
Can you share your configuration but changing some characters of token to keep anonymity?

Oh… I just noticed that I have an za2, and not a zb1…
It is just like the picture from the zb1 so I didn’t even reflect… I went to extract the tokens again to make sure it was correct, and noticed the “MODEL: zhimi.heater.za2”, don’t know if it could be the problem.
I have updated the “model” in the code, but it still gives me the same error.
My code is this (with changed token)

climate:
  - platform: miheater
    host: 192.168.50.166
    token: ff01b41b24cb953bccd633653b952cc0A
    name: xiaomi_heater
    model: zhimi.heater.za2

This is on server “DE”, if it helps in any way

The error is really strange. Is there anyway you can check that you have the correct token? It should be an hexadecimal string, and the error is saying it’s not.
Please confirm it only contains numbers and lowercase “a” to “f”.

Hi Sergio,
For some reason, this morning it started working. Maybe it still had something in the cache…
Either way, it works perfectly :smiley:
Thanks for all the help and patience :smiley:

1 Like

Hello @sergio_pt!

First of all, thanks a lot for your contribution, i have on of these heaters, and the integration is working so far!
Just some questions I got:

  1. How did you get those sensors for your card? sensor.thermostat_temperature, sensor.thermostat_setting & sensor.xiaomi_heater_switch? Are those template sensors? Can you share them?
  2. When I was configuring the integration, I first installed the repository into HACS, and restarted my HA instance before changing my config file, and HACS didn’t even boot up properly. After that, I completed the configuration, and after restarting, HACS was ok. Maybe this has something to do with a hang on the custom component?
  3. My climate entity shows this warning/error:
    This entity ("climate.zhimi_heater_mc2_64_90_c1_93_8f_02") does not have a unique ID, therefore its settings cannot be managed from the UI. See the [documentation](https://www.home-assistant.io/faq/unique_id) for more detail.
    Any idea? I can’t also change the entity id/name.

To finish up, I am not a very experienced Python developer, but I am professionally an SW developer, so if you need any help developing new features, fixing stuff or refactoring, let me know!
Cheers from Braga!

Hi Carlos,

Let me breakdown my answer and apologies for the delay, but I just got back to PC from the holidays :slight_smile:

Regarding the sensors for my card, I have used the below templates:

  - platform: template
    sensors:
      heater_switch:
        friendly_name: "Heater Switch"
        value_template: >-
          {% if is_state('switch.plug_heater', 'off') %}
            0
          {% elif is_state('switch.plug_heater', 'on') %}
            1
          {% endif %}
      xiaomi_heater_switch:
        friendly_name: "Xiaomi Heater Switch"
        value_template: >-
          {% if is_state('climate.zhimi_heater_mc2_5c_e5_0c_e0_1a_f7', 'heat') %}
            {{ state_attr('climate.zhimi_heater_mc2_5c_e5_0c_e0_1a_f7', 'current_temperature') }}
          {% elif is_state('climate.zhimi_heater_mc2_5c_e5_0c_e0_1a_f7', 'off') %}
            0
          {% endif %}

The second point you mention, is something that didn’t happen to me, there should be no issue in having an integration without a configuration, it would just mean that the instance does to instantiate it. But I really don’t know :frowning:

Regarding the third point, that warning happens because this integration is not using default Home Assistant integration configuration (it is still using yaml to initiate and get the token, versus configuring in “integrations”)

For the final point, this was my first python experience and I haven’t programmed in quite a few years now, so, if you want to check the code and fix it or add more functionalities, I would very much welcome it. :slight_smile: I believe the repository is public and you can make PRs.

Cheers from Lisbon!

1 Like

Hello Sergio!
No problem, don’t apologize for that :slight_smile:

Thanks for sharing, i tweaked it up a bit, but i get the point!

Blockquote
The second point you mention, is something that didn’t happen to me, there should be no issue in having an integration without a configuration, it would just mean that the instance does to instantiate it. But I really don’t know :frowning:

Yes, probably something related to HACS or smtg.

Blockquote
Regarding the third point, that warning happens because this integration is not using default Home Assistant integration configuration (it is still using yaml to initiate and get the token, versus configuring in “integrations”)

Ah ok, no problem then.

Blockquote
For the final point, this was my first python experience and I haven’t programmed in quite a few years now, so, if you want to check the code and fix it or add more functionalities, I would very much welcome it. :slight_smile: I believe the repository is public and you can make PRs.

Yes, the repo is public! Probably trying to put the configuration via UI, instead of YAML, would be a nice improvement. In the coming week, i’ll setup the development environment and try to play with it a bit.

Thanks a lot!

Hi!

I just discovered this heater “Xiaomi Smart Heater 1S” and I am considering buying a couple of them if they can integrate to Home Assistant (Which it seems they can thanks to your work - awesome, thanks!).

However I was wondering if it is possible to regulate the wattage on this heater? It seems like it is only possible to regulate the temperature? (Either with the integration or native app, or even the touch screen).

Let’s say I wanted to run it at just 1000W or something like that, is it possible?

Thanks.

1 Like

Hi!

It’s not possible to regulate the power. Not even from the Xiaomi app.
It is something it does internally based on it’s temperature sensor. I really wish we could do it, as I find its internal temperature sensor unreliable.

1 Like

Hey, thanks a lot for clarifying.
That is a shame, as most normal heaters usually have at least 2-3 power settings.
But that is what I feared while looking at the details and specifications.
2200W is basically a whole 10A circuit, so it would be nice to have some control over it.
I might have to reconsider, or maybe just buy 1 instead of 2 as I first planned.
Are you happy with it besides this?