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.