I cannot for the life of me get the utility meter to reset to zero each day

Thanks for taking the time to do this.
I have configured this in to my system. Let’s see what happens tomorrow. (It might be the day after as the inverter has already shut down).
Edit: Is there a good site or YT video I can watch where I can learn yaml?
I used to program in C a bit, but I was never any good at it.

1 Like

YAML is just a way to represent data. Any tutorial on that is fine, but you need only the basic knowledge of that.

The way Home Assistant uses YAML to store automations, scripts, scenes, templates. etc. is a reflection on how HA defines the data for it.The data structure HA defines what is stored in YAML. So there are no general courses on that. Plus, since HA releases every month, any tutorial will quickly be out of date in some way or another. It is the same reason why AI fails so miserably at writing it. Don’t use it. It is bad at it, will invent things HA does not allow and you’ll learn bad things from it.

So for learning that: using the automation editor and see what comes out. It is always correct. Look at the extensive documentation: it always describes the last version of what fields you can use. It also holds examples to get you started. The documentation is the description of what is valid HA YAML. Read the forum a lot, don’t be afraid to ask and try things for yourself.

And then there is Jinja2 templating. That is a language of its own, and HA uses a specific version of it. Also here: a generic course can teach you the basics. Here too the language itself it just a starting point. You can use some python functions, and the HA documentation defines Home Assistant specific functions. (Not to mention that storing Jinja templates in YAML is somewhat awkward, requiring quotes to be there or not be there depending on there you put it.)

This is what HA adds to jinja to interact with HA:

All those layers put together form a powerful, but HA specific mix.

I take it that this goes into configuration.yaml?
If I put the - preceding the trigger I get this error:
13 | - trigger:
------^
14 | - trigger: state
If I take the - out, I get the green tick but then get this error when I check the configuration before rebooting:
Invalid config for ‘sensor’ at configuration.yaml, line 22: required key ‘platform’ not provided
Integration error: trigger - Integration ‘trigger’ not found.

Tom,
If create two counters and set them to hold their values during reboot.
counter.consumption_energy_holding
counter.export_energy_holding
I can’t for the life of me figure out Yaml syntax, but this is how I would do it in C:

If (sensor.solax_swapuwz36r_total_consumption_energy > counter.consumption_energy_holding )
   {
   counter.consumption_energy_holding = sensor.solax_swapuwz36r_total_consumption_energy ;
   }

Then base my utility meter on counter.consumption_energy_holding
Would that work, or does the counter have to be a type of power?
If it would work ,can you write me the yaml?

This worked:
It doesn’t copy the value unless the AC output from the Solax inverter is above zero. Pvoutput didn’t like the negative export values (consumption), this had to be inverted.

template:
    - sensor:
      - name: "Corrected Negative Export"
        unique_id: "corrected_negative_export"
        device_class: "power"
        state_class: "measurement"
        unit_of_measurement: "W"
        state:  "{{ [0, states('sensor.solax_swapuwz36r_exported_power' ) | int * -1] | max }}"
      
    - trigger:
      - platform: state
        entity_id: sensor.solax_swapuwz36r_ac_power # Replace with your actual entity ID
    - sensor:
      - name: "My Consumption Sensor"
        #device_class: energy
        #state_class: total
        unique_id: my_consumption_sensor
        state: >
          {% if states('sensor.solax_swapuwz36r_ac_power') | float(0) > 0 %}
            {{ states('sensor.solax_swapuwz36r_total_consumption') }}
          {% else %}
            {{ states('sensor.my_conditional_sensor') }}
          {% endif %}
        unit_of_measurement: "kWh" # Replace with your actual unit 
        
    - trigger:
      - platform: state
        entity_id: sensor.solax_swapuwz36r_ac_power # Replace with your actual entity ID
    - sensor:
      - name: "My Feed in Sensor"
        #device_class: energy
        #state_class: total
        unique_id: my_feed_in_sensor
        state: >
          {% if states('sensor.solax_swapuwz36r_ac_power') | float(0) > 0 %}
            {{ states('sensor.solax_swapuwz36r_total_feed_in_energy') }}
          {% else %}
            {{ states('sensor.my_feed_in_sensor') }}
          {% endif %}
        unit_of_measurement: "kWh" # Replace with your actual unit