Mini-D Thermostat Sensor

hey,
Just wanted to share with you my new template sensor. I wanted to know when my gas heating boiler was on and for how long and who triggered the hvac_action. Just got the new Sonoff Mini-D switches and was able to create a generic thermostat with it to turn on and off my heating system.
Here is my template:

template:
  - trigger:
      - platform: state
        entity_id:
          - climate.thermostat_living
          - climate.thermostat_girlies
          - climate.thermostat_master_bedroom
          - climate.thermostat_back_up
        variables:
          ts_format: "%Y-%m-%d %H:%M:%S"
    condition:
      - condition: template
        value_template: "{{ trigger.from_state.attributes.hvac_action != trigger.to_state.attributes.hvac_action }}"
    binary_sensor:
      name: Heating
      icon: >-
         mdi:fireplace{{ '' if trigger.to_state.attributes.hvac_action == 'heating'  else '-off' }}
      state: >-
        {{ 'on' if trigger.to_state.attributes.hvac_action == 'heating' else 'off' }}
      attributes:
        last_on: |
            {{ now() if trigger.from_state.attributes.hvac_action == 'idle' else state_attr('binary_sensor.heating', 'last_on') }}
        last_off: |
            {{ now() if trigger.from_state.attributes.hvac_action == 'heating' else state_attr('binary_sensor.heating', 'last_off') }}
        triggered_by_entity_id: |
            {{ trigger.entity_id }}
        trigger_by_friendly_name: |
            {{ state_attr('binary_sensor.heating', 'trigger_by_friendly_name') }}
        on_for: >-
          {% set t = 0 if trigger.to_state.attributes.hvac_action == 'heating' else now().timestamp() - as_timestamp(state_attr('binary_sensor.heating', 'last_on'),default=now().timestamp()) %}
          {{ t | timestamp_custom('%H:%M:%S', false) }}
        hvac_action: >-
          {{trigger.to_state.attributes.hvac_action}}`

Maybe it helps someone.
You’re welcome to improve.