Do an automation if state value contains partial string

I got a sensor that tells me when the next time the mail is delivered to my house. Have created a custom:button card that I want to blink when the day is tomorrow and today.
The string value for tomorrow is always: Tomorrow ‘Name of day’ ‘Date’ ie: Tomorrow Thuesday 21.03.23

type: custom:button-card
entity: sensor.postendeliverydays
icon: mdi:mail
color: rgb(33,150,243,255)
show_state: true
name: Mail delivery
state:
  - value: Tomorrow
    color: green
    styles:
      icon:
        - animation:
            - blink 2s linear infinite
      name:
        - color: green
        - font: 17px Roboto
      state:
        - color: green

How can I make it trigger on only parts of the value?

Show us the sensor instead the card has nothing to do with automation

- platform: rest
    name: PostenDeliveryDays
    resource: https://www.posten.no/levering-av-post/_/component/main/1/leftRegion/11?postCode=7300
    headers:
      x-requested-with: XMLHttpRequest
    scan_interval: 57600
    value_template: "{{ value_json.nextDeliveryDays [0] }}"

I think your beat option is to make a template binary sensor with the value_template:

{{ "Tomorrow" in states('sensor.postendeliverydays') }}

This should return true or false and if you use this in your button card then it should work.
I can’t seem to find anything about templates in this card or any way to control them other than the configuration you have.
So by using a binary sensor it should be easy.

1 Like

Thanks!
Is there a way for me to use the card that I have and make it blink based on status from the new entity?
image
I really want the date to show.

  - platform: template
    sensors:
      postutlevering:
        friendly_name: "Postutlevering"
        value_template: "{{ 'i dag' in states('sensor.postendeliverydays') }}"```

You made it a sensor, not binary sensor.
But it should return true or false I guess.

Won’t that work in you previous card yaml?

type: custom:button-card
entity: sensor.postutlevering
icon: mdi:mail
color: rgb(33,150,243,255)
show_state: true
name: Mail delivery
state:
  - value: true # or True
    color: green
    styles:
      icon:
        - animation:
            - blink 2s linear infinite
      name:
        - color: green
        - font: 17px Roboto
      state:
        - color: green

I’m pretty new to HA and I better at copy/paste then coding :slight_smile:
But with your solution the date for the next delivery will not show.
image

type: custom:button-card
entity: sensor.postutlevering
icon: mdi:mail
color: rgb(33,150,243,255)
show_state: true
name: Postutlevering
state:
  - value: "True"
    color: green
    styles:
      icon:
        - animation:
            - blink 2s linear infinite
      name:
        - color: green
        - font: 17px Roboto
      state:
        - color: green

What does this sensor say in developer tools → states sensor.postutlevering

image

What happens if you test this template in template tools:

{{ states('sensor.postutlevering') }}
{{ states('sensor.postutlevering') == true }}
{{ states('sensor.postutlevering') == "true" }}
{{ states('sensor.postutlevering') == "True" }}

Top and bottom show True. The rest shows false.

To be clear that we are on the same page.

type: custom:button-card
entity: sensor.postutlevering
icon: mdi:mail
color: rgb(33,150,243,255)
show_state: true
name: Postutlevering
state:
  - value: "True"
    color: green
    styles:
      icon:
        - animation:
            - blink 2s linear infinite
      name:
        - color: green
        - font: 17px Roboto
      state:
        - color: green

This code works. The icon is green and it is blinking.

What I’m missing is the date. I wouldn’t assume that I’ll get the date with sensor.postutlevering as this sensor will just have value true or false.

What I’m looking for is a way for a card to show the date from sensor.postendeliverydays and make that card blink if sensor.postutlevering = true.

I don’t think you can have both.
Because the card doesn’t seem to accept templates then it can’t do both.
At least not that I know

Thank for the help. It blinks when the mail is coming now. Hopefully I’ll find a card some day that can act on the state of another entity.

Found the solution:

type: custom:button-card
entity: sensor.postendeliverydays
icon: mdi:mail
color: rgb(33,150,243,255)
show_state: true
name: Postutlevering
state:
  - value: "i dag"
    operator: regex
    color: green
    styles:
      icon:
        - animation:
            - blink 2s linear infinite
      name:
        - color: green
        - font: 17px Roboto
        - animation:
            - blink 2s linear infinite
      state:
        - color: green
        - animation:
            - blink 2s linear infinite