Host Platform: how to?

Hi everybody,

I tried setting up Host Platform, but it doesn’t seem to do anything. Below is my config as well as the debug log.

esphome:
  name: hosttest
  friendly_name: HOSTTEST
  area: Arbeitszimmer

# Example configuration entry
host:

button:
  - platform: template
    name: Testbutton
    on_press:
      then:
        - logger.log: Button Pressed

# Enable logging
logger:


# Enable Home Assistant API
api: 
  encryption:
    key: !secret encryption_key

I ran this on my desktop via esphome run hosttest.yaml.

INFO Successfully compiled program.
DEBUG Running:  /mnt/hass/esphome/.esphome/build/hosttest/.pioenvs/hosttest/program
[13:06:58][I][app:029]: Running through setup()...
[13:06:58][C][api:026]: Setting up Home Assistant API server...
[13:06:58][I][app:062]: setup() finished successfully!
[13:06:58][W][component:157]: Component api set Warning flag: unspecified
[13:06:58][I][app:100]: ESPHome version 2024.10.3 compiled on Nov 15 2024, 13:06:47
[13:06:58][C][logger:185]: Logger:
[13:06:58][C][logger:186]:   Level: DEBUG
[13:06:58][C][mdns:116]: mDNS:
[13:06:58][C][mdns:117]:   Hostname: hosttest
[13:06:58][C][api:140]: API Server:
[13:06:58][C][api:141]:   Address: :6053
[13:06:58][C][api:143]:   Using noise encryption: YES

That’s it. There will be no further output.

My host computer is on the same network as Home Assistant. I made sure to disable my firewall, in case it interfered with this. No difference. I ran esphome clean hosttest.yaml in between tries.

Perhaps this is related to the API component, but unspecified doesn’t help me much. Have any of you successfully gotten this to run?

Thanks in advance :slight_smile:

What are your expectations?
This should create an ESPHome instance on your desktop/laptop computer that you can add to HA. The only exposed entity will be a button.

How far did you go?

I have the same question as @koying , what do you want to do? Or more specifically, why do you think you need the Host Platform?

In three years of programming ESPHome projects, this is the first time I had ever heard of Host Platform.

1 Like

Did you add your desktop as a device in the HA ESPHome integration? It won’t find it automatically.

1 Like

Thank you @clydebarrow
That did it. I assumed it would be auto-discovered, because I haven’t had any device not being auto-discovered yet… but manually adding it worked just fine.

@koying

How far did you go?

I did as far as I described in my initial post. It included my steps and the log. My error was not to add the device to Home Assistant manually.

What are your expectations?
(…)
The only exposed entity will be a button.

This. I wanted this button in Home Assistant to see whether this worked. I did not see the button because the device had not automatically been discovered by Home Assistant. Now that I added it, I do see the button and get the desired output when pressing it (log in command line on Host PC, registered button press within Home Assistant).

I can build from there.

@stevemann I don’t know if/how much you experiment with ESPHome, but I find it much easier to do it this way than to flash an ESP, test something, change something, re-flash it, test again, re-flash again, etc. etc.

Now I can try things (custom_components, lambda stuff) without all these steps. Edit my yaml, run it locally, have it in Home Assistant. No ESP device needed, no flashing.

I have also found that some ESPs don’t like being flashed countless times. Some would not respond after a while, others would not (seem to) accept the changes. So I’d change a bunch of things in my yaml, flash it wirelessly, get the “success” output, but nothing had changed - the ESP was still flashed with the previous firmware (or rather, some previous firmware, perhaps one four flashes ago). This could be circumvented by erasing the flash before flashing the new firmware, which, as you can imagine, is also quite bothersome.

This allows me to test stuff without all these steps, and, in fact, without even having to have a spare ESP that I can test stuff on.

this is the first time I had ever heard of Host Platform.

Have you heard of the tankerkönig integration? It will show you gas prices for German gas stations. Unless you live in Germany and like to keep track of such things, you might have never heard of it. Doesn’t mean it isn’t helpful if one needs it :wink:

1 Like

This host: platform is really great - I just realized that you can create a linux desktop widget to show any Home Assistant sensor!

I’m using the host platform to debug LVGL displays for ESP32C3, and this allows me to debug them without downloading the firmware to the ESP32 every time I want to play with the widget positions - it is far better than using an LVGL simulator.

It has great potential for sure.

I use it mostly as a system monitor here on my Linux host. It actually works better with Home Assistant than Home Assistant’s System Monitor integration because I can filter the sensors easily. This not only means nicer looking graphs but also faster response to changes and reduced impact on the database size.

I got five sensors so far:

Example code for one of the sensors:

  - platform: template
    name: "Root Disk Usage"
    icon: "mdi:harddisk"
    unit_of_measurement: "%"
    state_class: measurement
    accuracy_decimals: 0
    update_interval: 30s
    filters:
      - or:
        - delta: 1
        - throttle: 15min
      - round: 0
    lambda: |-
        struct statvfs vfs;
        if ( statvfs ( "/", &vfs ) < 0 ) { perror( "statvfs" ); return NAN; }
        return 100.0 * ( vfs.f_blocks - vfs.f_bfree ) / ( vfs.f_blocks - vfs.f_bfree + vfs.f_bavail );

I also figured out how to run the ‘host:’ platform in a docker container. So for those who got a docker home assistant install it should be fairly easy to deploy. https://github.com/MeisterSchlaueLampe/esphost-laboratory/tree/main/esph-sysmon

2 Likes

Wow, fantastic work!

Is this

  lambda: |-
        struct statvfs vfs;
        if ( statvfs ( "/", &vfs ) < 0 ) { perror( "statvfs" ); return NAN; }
        return 100.0 * ( vfs.f_blocks - vfs.f_bfree ) / ( vfs.f_blocks - vfs.f_bfree + vfs.f_bavail );

Code that runs within the Host platform, but on your computer? In other words, could you run this as .c-code (I believe that’s what it is?) on your PC and get the same output?

Auf jeden Fall echt schlau.

I just wish Host would work with Home Assistant sensors. I was trying to generate an eink display via host, but I cannot get data from within Home Assistant (for example sun.sun, binary_sensor.xyz123, etc.)

This output can be hard-coded for testing, but it isn’t the same. Neither mqtt, nor reading directly from HA, seems to be possible. Or is it and I just did it incorrectly?

Would be much nicer testing live output via host, then flashing it to an actual display once everything work as expected.

Why shouldn’t it? :thinking:

Probably… How could we know?

It does. The only caveat is that HA will not discover the host instance as mDNS is not implemented on host, you have to add it by IP address manually. Otherwise it all works as expected.