Can I ensure a measurement was transmitted to HA?

Dear all,

I am just trying to read a smart meter. Now I want to wake up the ESP32 every 15 mins, read a couple of values, and as soon as all of them are read, I want to send the devide to sleep again.

Is there any option to ensure whether a sensor has transmitted its data to HA successfully within the YAML code? I observe the on_value action simply confirms the value was read - is there any equivalent for the communication using HA’s native API?

Thanks!

You can use logger, Logger Component — ESPHome

@nickrout Sorry, I was referring to checking this in the YAML file during a running script. I edited my post to clarify this.

Thanks!

When a reading is sent to HA, then esphome logs it, and you can test for successful delivery by using the automation trigger I pointed you to.

Okay, thanks

But this will trigger whenever any message is logged to the logger, right?

So I cannot be sure which entry was added, right?

Or would I have to play around with debug levels, adding certain sensors to certain levels?

I see from the link above you can post a context message log. It would be triggered by a sensor automation. And would be clearly visible

Alternatively use the ESPHome Status component. In HA use a template trigger to check on the binary sensor status and whether your sensor value is received by the next disconnection

I found the post I was thinking of, it is a bit more complicated than I remembered.

@nickrout, @JulianDH : I am sorry, but I am quite new to ESPhome and HA. So I have some issues to understand your hint. Say, I have an sml object and some sensor power of platform type SML - could you help me with a simple example?

In the end I want to send the ESP to deep sleep to save battery power, but I want to be sure a measurement was transferred before the device sleeps. So I tried this

sml:
  id: mysml
  uart_id: uart_bus


sensor:
  - platform: sml
    name: "Power"
    sml_id: mysml
    obis_code: "1-0:1.8.0"
    unit_of_measurement: kWh
    accuracy_decimals: 4
    id: power
    device_class: energy
    state_class: total_increasing
    filters:
      - throttle: 10s
      - multiply: 0.0001 
    on_value:
      then:
        - switch.turn_on: energy_was_read
        - script.execute: consider_deep_sleep

logger:
   on_message:
    - if:
        condition:
            lambda: !lambda |-
              return tag=="sml";
        then:          
          - switch.turn_on: SML_data_written_to_log
          - script.execute: consider_deep_sleep

but the switch in the logger is never turned on. As the deep sleep checking function checks for all switches to be positive, the device never goes to sleep.

Is this understandable, or should I post the full code?