How to Get Last State Changed from Switch?

What you have written is correct but HA needs to know what to monitor for updates. For that you need to supply an entity id to monitor. Try this:

- platform: template
    sensors:
      last_fish_feed_time:
        entity_id: switch.turn_on_fish_feeder # Entity to monitor for changes
        friendly_name: "Last Fish Feeding Time"
        value_template: "{{as_timestamp(states.switch.turn_on_fish_feeder.last_changed) | timestamp_custom('%A %d-%b-%y, %H:%M:%S')}}"
1 Like