Restore last known value from solar upon reboot

Hi, I have a Growatt solar system in my house, the cloud integration was tarrible and I’ve flashed my ShineWiFi-X dongle with this: https://github.com/otti/Growatt_ShineWiFi-S

Then via MQTT it sends the data to HA, my yaml:

mqtt:
  sensor:
     - state_topic: "energy/solar"
       name: "Panele góra całkowita"
       unit_of_measurement: "kWh"
       value_template: '{{ float(value_json.TotalGenerateEnergy) | round(1)  }}'
       json_attributes_topic: "energy/solar"
       device_class: energy
       state_class: 'total_increasing'    
       last_reset_value_template: '1970-01-01T00:00:00+00:00'
       payload_available: 1 # you might need to adapt this
       availability_mode: 'latest'
       availability_topic: "energy/solar"
       availability_template: '{{ value_json.InverterStatus }}'
     - state_topic: "energy/solar"
       name: "Panele góra dzisiaj"
       unit_of_measurement: "kWh"
       value_template: '{{ float(value_json.TodayGenerateEnergy) | round(1)  }}'
       json_attributes_topic: "energy/solar"
       device_class: energy
     - state_topic: "energy/solar"
       name: "Panele góra moc"
       unit_of_measurement: "W"
       value_template: '{{ float(value_json.OutputPower) | round(1)  }}'
       json_attributes_topic: "energy/solar"
       device_class: energy
     - state_topic: "energy/solar"
       name: "Panele góra V"
       unit_of_measurement: "V"
       value_template: '{{ float(value_json.L1ThreePhaseGridVoltage) | round(1)  }}'
       json_attributes_topic: "energy/solar"
       device_class: power

Everything works great but at night the solar inverter turns off and there is no power to the ShineWiFi-X dongle. HA keeps the last known state showing, but if I restart my HA (for updating) the instances show as unavailable. Is there a way to save the last known state of these entities and restore it upon reboot if there is no connection to my solar inverter?

You need to set the inverter dongle to send the state messages with the retained flag set.

That way when home assistant starts up and subscribes to the topics the broker will send the last known states.