################################################################
## Packages / MQTT - Publish Sensors
################################################################

automation:
  - alias: mqtt_publish_sensors
    hide_entity: true
    initial_state: 'on'
    trigger:
      - platform: event
        event_type: state_changed
    condition:
      - condition: template
        value_template: "{{ trigger.event.data is not none }}"
      - condition: template
        value_template: "{{ trigger.event.data.entity_id is not none }}"
      - condition: template
        value_template: "{{ trigger.event.data.new_state is not none }}"
      - condition: or
        conditions:
          - condition: template
            value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'binary_sensor' }}"
          - condition: template
            value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'sensor' }}"
    action:
      - service: mqtt.publish
        data_template:
          topic: "home-assistant/{{ trigger.event.data.entity_id|replace('.', '/') }}"
          payload: "{{ trigger.event.data.new_state.state }}"
          retain: true

Add MQTT sensor publishing package
Add MQTT sensor publishing package
