Skip to content

Conversation

@cristianchelu
Copy link
Contributor

Works pretty well.

Only quirk is an unknown country_code command spammed by the MCU; device works fine despite this.

[08:20:07.959][I][app:185]: ESPHome version 2025.9.1 compiled on Oct 11 2025, 07:42:42
[08:20:07.960][I][app:187]: Project dhewg.esphome-miot version zhimi.airp.meb1
[08:20:09.798][W][miot:399]: Unknown command 'country_code'
[08:20:15.329][W][miot:399]: Unknown command 'country_code'
[08:20:20.751][W][miot:399]: Unknown command 'country_code'

Sending set_properties 9 11 17749 shuts it up with this trace:

[08:21:59.728][W][miot:399]: Unknown command 'country_code'
# `set_properties 9 11 17749` from HA
[08:22:00.684][W][miot:257]: Received property value without component: 9 11 17749
[08:22:05.908][W][miot:399]: Unknown command 'country_code\x00EU'
[08:22:06.003][W][miot:399]: Unknown command 'country_code'

and adding a select entity fails at compilation

select:
  - platform: miot
    id: country_code
    name: country-code
    miot_siid: 9
    miot_piid: 11
    options:
      "17230": CN
      "17749": EU
      "19282": KR
      "21591": TW
      "21835": UK
      "21843": US
Compiling .pioenvs/hallway-purifier/src/main.cpp.o
src/main.cpp: In function 'void setup()':
src/main.cpp:1163:36: error: narrowing conversion of '17230' from 'int' to 'unsigned char' [-Wnarrowing]
 1163 |   country_code->set_select_mappings({17230, 17749, 19282, 21591, 21835, 21843});
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*** [.pioenvs/hallway-purifier/src/main.cpp.o] Error 1
========================= [FAILED] Took 12.77 seconds =========================

Also added template power/energy sensors based on kill-a-watt readings -- I can move this to the wiki if you don't want it in the standard config.

@dhewg
Copy link
Owner

dhewg commented Nov 20, 2025

Sorry, just noticed this now, I fail at notifications...

Feels like ages since I did anything with esphome, but thinking out loud:

  • you want to calculate the current and accumulated power usage
  • active_power has an update interval of 1s, hence you need the time /1 speed polling with the matching interval
  • where does that fancy active_power formula come from?
  • does the kWh sensor match the actual wall readings? I would expect some seconds to hour (60*60=3600) conversion?

@dhewg
Copy link
Owner

dhewg commented Nov 20, 2025

If you remove the quotes from the country numbers, and change the two uint8_t to uint32_t in components/miot/select/miot_select.h, does the country thing work then?

@cristianchelu
Copy link
Contributor Author

you want to calculate the current and accumulated power usage

Correct. Like having a smart power plug attached, without the extra hardware.

active_power has an update interval of 1s, hence you need the time /1 speed polling with the matching interval

The more detailed the fan speed graph is, the better the total energy estimates get, more on that below. 1 Hz polling might be overkill or not, but I didn't dwell too much on this number.

where does that fancy active_power formula come from?

I made a spreadsheet with 1 minute average power measured at 100rpm intervals, and fitted a cubic function over the plot for the fan; then reorganized the terms for more efficient computation. I also measured the constant UV/Ionizer consumptions.

does the kWh sensor match the actual wall readings?

Here's an hour of tracking versus an Ikea inspelning power socket, the estimation stays comfortably within half a Watt of measurements. Also on the energy tracking, both the socket and the estimate energy sensor agree on 0.004kWh for the period.

Screenshot 2025-11-20 at 17 08 44

I don't have a spare plug though to check over e.g. a week. I'm not aiming for 100%, just a reasonable ballpark of usage.

I would expect some seconds to hour (60*60=3600) conversion?

(mainsplaining warning, apologies in advance)
The integration sensor just does the "Area under the curve" mathematical integration from a source sensor, which is exactly the total energy consumed within whatever monitored time period. This is why having a more detailed fan speed (thus power) graph results in better energy estimation.

The same 24kWh energy consumption can be 24_000W sustained over exactly one hour or 1000W sustained over 24h, or even 48kW for half an hour. Or in way more detail video form: Power is not energy

If you remove the quotes from the country numbers, and change the two uint8_t to uint32_t in components/miot/select/miot_select.h, does the country thing work then?

I'll check this over the weekend and get back to you.

@dhewg
Copy link
Owner

dhewg commented Nov 20, 2025 via email

@cristianchelu
Copy link
Contributor Author

1s interval may clobber the serial line, does the rpm really fluctuate
that much?

I have the same setup in my Purifier 4 working without a hitch since I first submitted a PR for it aeons ago, so I would say it's safe.

I'm not interested as much in the 10rpm differences at steady state, just need to precisely detect the large changes (i.e. 100% or nearly - to min speed) as these will affect the "area under the graph" that's summed up.

but 3s may be a less aggressive yet sufficient default?

This is a question I'll leave to nerdier people with more free time to answer. 😄

This is also part of the reason I mentioned having these optional "addon" sensors in the wiki -- just that visibility suffers there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants