kWh s0 pulse and high/low rate

I have my P1 smart meter connected to Home Assistant and it is visible now in the energy dashboard.

On one of my wall outlets, I have a kWh meter connected.
kWh meter with pulse

This meter has a S0 pulse output, and every pulse represents one used Watt.
I did use this meter with Domoticz. Every counted pulse was directly forwarded to Domoticz. Because I have a contract with high and low rates, the esp looked at the day (weekend or not) and time, to determine which rate has to be used.
Than Domoticz has three counter: high rate, low rate and total.

But now over to Home Assistant.
How can I best log the energy usage of this wall outlet with these S0 pulses?

Do I have to do this with esphome and is it possible than to see high and low rate usages?
Do I have to programm the esp myself so this esp can determine if the high or low rate is applicable?
Do I better use some mqtt to get this right?

I hope to combine thos values (high/low/total) in one card and I want to be able to see totals per day/week/month/year, like the energy dashboard.

Can someone point me in the right direction, or maybe give me some examples?