logo elektroda
logo elektroda
X
logo elektroda

Home Assistant entity data to ESP32 via WiFi for RS485 HMI display integration

Tarnus 159 2
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 21533781
    Tarnus
    Level 20  
    Hello.
    I have mounted a Chinese HMI display next to the inverter, which has two RS485 ports. I set the first port as master and I download data from the photovoltaic inverter via this route. The HMI displays these downloaded parameters. I set the second port on the HMI as a slave. This port is connected to an ESP32 with WiFi activated. The Home Assistant connects over WiFi to this ESP32 and downloads the inverter parameters available to the HMI. I would also like to display some relevant parameters from the heat pump and other devices in the house on this same HMI. The pump sends its parameters to the HA via a second ESP32, also running WiFi. Currently I already have several of these ESP32s and more will be coming. This is where I have a problem. I cannot in any way send the value of any entity from the HA to this ESP32, which is connected with the HMI. How do I bite into this? How do I send the value of any entity from the HA to the ESP32? I send from ESP32 as master to slave HMI seamlessly, but not from HA to ESP32. It looks like this, as if the entity in the HMI is a global value.
  • ADVERTISEMENT
  • #2 21534533
    xury
    Automation specialist
    And what do you have on this ESP32? EspHome? Tasmota? Or some code of your own?
  • #3 21535194
    Tarnus
    Level 20  
    >>21534533 I was just about to write that I managed to solve the problem. The answer to your question is that all the ESP32s I have are from ESPHome.
    Below are excerpts from the script responsible for getting the entity value from HA and sending it to the modbus slave using ESP. I have tried a number of ways. There may be other/better solutions, I'd be happy to hear about them. For now, the important thing is that the one below works:

    captive_portal:

    uart:
    id: mod_bus
    tx_pin: 17
    rx_pin: 16
    baud_rate: 9600
    stop_bits: 1

    modbus:
    id: solar_hmi_modbus
    send_wait_time: 200ms

    modbus_controller:
    - id: "${devicename}"
    address: 0x1
    modbus_id: solar_hmi_modbus
    setup_priority: -10
    update_interval: 10s


    sensor:
    - platform: homeassistant
    id: ${devicename}_test_counter_inflation
    entity_id: sensor.counter_inflation

    - platform: template
    id: "${devicename}_test_test"
    internal: true
    lambda: |-
    uint16_t value = id(${devicename}_test_count_test).state;
    esphome::modbus_controller::ModbusCommandItem set_payload_command = esphome::modbus_controller::ModbusCommandItem::create_write_single_command(${devicename}, 0x96, value);
    ${devicename}->queue_command(set_payload_command);
    return {};
ADVERTISEMENT