Stray Cat Status - Need Help Thinking This Through

Hello everyone. New to HA (well, been fiddling for a month). This is my first post here. I’m kind of stuck and hoping for some help. Here’s what I’m trying to do:

We have a stray cat. I want a display on the dashboard that shows, starting at 8 AM that the stray cat is out and about. I currently have DOODS AI watching our outdoor camera and checking for cats. As soon as it detects a cat, I want that display to change to “Cat is home; needs food.” At that point, one of us will feed the cat, and then manually press the display, which will change it to “Cat fed.” It should remain that way until 8 AM.

I’ve got most of this figured out. I created a sensor in my YAML for this purpose:

template:
  - sensor:
    - name: "Black Kitty"
      state: away

I also created a Mushroom Template card that mostly works:

      - type: custom:mushroom-template-card
        primary: |-
          {% if is_state('sensor.black_kitty', 'away') %}
          Adventuring
          {% elif is_state('sensor.black_kitty', 'hungry') %}
          Awaiting noms...
          {% else %}
          Home and fed!
          {% endif %}
        picture: >-
          https://i.pinimg.com/originals/da/45/59/da45599388682ff2b2365ba23c126a44.jpg
        badge_icon: |-
          {% if is_state('sensor.black_kitty', 'away') %}
          mdi:paw
          {% elif is_state('sensor.black_kitty', 'hungry') %}
          mdi:food
          {% else %}
          mdi:home
          {% endif %}
        badge_color: |-
          {% if is_state('sensor.black_kitty', 'away') %}
          grey
          {% elif is_state('sensor.black_kitty', 'hungry') %}
          red
          {% else %}
          green
          {% endif %}
        tap_action:
          action: none
        hold_action:
          action: none
        double_tap_action:
          action: none
        icon: ''
        secondary: last-changed
        entity: sensor.black_kitty
        multiline_secondary: false

What I don’t know how to do is configure the tap_action event to change the sensor from “hungry” to “fed”. In my Googling I’m starting to thing doing this with a “sensor” is not the right way to do it. Is there a better way of accomplishing what I’m trying to do here? I haven’t gotten to the other two automations (one triggered at 8 AM, and one triggered by the AI) which will also need to change the state of the sensor, but I assume this is all possible - but maybe not in the manner in which I’m trying to accomplish it?

Many thanks in advance!

image

Rather than using a template sensor, you could use a dropdown helper (input_select) that accepts values “away”, “hungry”, “fed” (etc). Then the tap_action would call the “input_select.set_option” service to select “fed”. Another automation would need to set it back to “away” at 8am. You would also need to ensure you only set it to “hungry” if it’s currently “away” so you don’t end up with a fat cat.

Alternatively, if you’re already using MQTT, you could create an MQTT sensor and publish a message with the appropriate state (and using retain to cope with HA restarts).

Thank you so much! That was all I needed to get everything working!

I have one final question. In my Mushroom Template code, everything works fine, except for my secondary information line. As you can see from my screenshot, it just says “last-changed” rather than the actual timestamp of the last time the state of the helper changed. Can you possibly lend me any clarity on how to get that working?

The last changed property would be “last_changed” (underscore rather than hyphen). However, I think on this card it needs to be coded as a template:

{{ states.input_select.black_kitty.last_changed }}

However, that’s going to look pretty ugly, so you could format it better with:

{{ states.light.kitchen.last_changed | as_timestamp | timestamp_custom('%Y-%m-%d') }}

Unfortunately none of those seem to work. It seems to refuse to accept anything that isn’t simply a string. If I do anything else, the preview either disappears entirely, or you get an endless “spinning wheel of thought.”