Shelly EM sensor

I have a Shelly EM and want to record the length of time my pool runs each day. I have created the following sensor but it has the run time as 0.0 even though the pump has been running.

  • platform: history_stats
    name: Pool pump run time today
    entity_id: sensor.shellyem_a4e57cba99c7_channel_2_power
    state: ‘on’
    type: time
    start: ‘{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}’
    end: ‘{{ now() }}’
    I presume that the EM does not have an on/off state and this is why is it not working. Could I create a sensor to record the time that the the energy consumption is greater that 1kw to achieve the same result and what would this look like?

Please format your pasted conifig like this in future: https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

Create a template binary sensor like this:

(configuration.yaml)

template:
  - binary_sensor:
      - name: "Pool Pump"
        device_class: running 
        state: "{{ states('sensor.shellyem_a4e57cba99c7_channel_2_power')|float(0) > 100 }}"
        availability: "{{ states('sensor.shellyem_a4e57cba99c7_channel_2_power')|is_number }}"

Change the number 100 to half the power observed when your pump is running.

Use this binary sensor (binary_sensor.pool_pump) in your history stats sensor.

Thanks for the help. It now works as hoped.