Display Modbus Online/offline status on OLED display

Hi,

I have setup an Esp32 with ESPhome and home assistant and it works great.

I also have a little OLED screen displaying some basic information such as IP address etc.

I am trying to configure this setup to show in the OLED screen when the modbus server is online and connected to my inverter but for the life of me I cant.

I saw there is an automation option with Modbus to trigger actions using but cant get the code to work in a way that I can use the print command to display in the OLED

Any help with some code examples would be much appreciated - not an expert by any means

Thank you

modbus_controller:
  - id: modbus_con
    # ...
    on_offline:
      then:
        - logger.log: "Controller goes offline!"

You could make a template sensor to show modbus state:

binary_sensor:
  - platform: template
    name: "Modbus State"
    id: mbstate

Then update the state on modbus controller

on_offline:
      then:
        - binary_sensor.template.publish:
            id: mbstate
            state: OFF
on_online:
      then:
        - binary_sensor.template.publish:
            id: mbstate
            state: ON

And print the mbstate in your display component…

Thank you Karosm

Fantastic - learned something new today - it worked perfectly

Thanks

Nice!
All template sensors are handy when you don’t want to write C++ in lambdas.

1 Like