Is it possible to add a "Time since ..." to a picture element card?

Hi everybody! :slight_smile:

I just got a temperature monitoring system up and running for my central heating system. Will be useful when determining efficiency and to monitor wood consumption. I’m still very new to coding/scripting and struggle a bit from time to time. Now I kinda managed to make a half decent picture element card but now I’m stuck :confused:

What I do want to add is a text and a counter that says “Time since last fire” or something like that and then have a counter expressed in days and hours. To get the “start time” of the counter I will use the power state of a smart plug. There is a fan inside the boiler which pulls around 200W when in use. So I figure something like “Counter should start counting when power usage of smart plug goes under 150W, and reset for another count when power usage goes over 150W”

However, I also start the fan when cleaning the boiler, thus the power usage will go over the threshold. Is it possible to add “When power >150W for 30 minutes” to the reset?

I also would like to add “Total number of fires this year” to the picture element card, following the same logic as above. One cycle of power usage >150W for at least 30 minutes would mean 1 fire to add to the count.

Any help in the right direction would be really appreciated! :grinning:

This is what the card looks like:
2

My code so far:

elements:
  - type: state-label
    entity: sensor.panna
    style:
      top: 25%
      left: 72%
      font-size: 16px
      color: black
  - type: state-label
    entity: sensor.tekniktank_1
    style:
      top: 34%
      left: 42%
      font-size: 16px
      color: black
  - type: state-label
    entity: sensor.slavtank_1
    style:
      top: 34%
      left: 15%
      font-size: 16px
      color: black
  - type: state-label
    entity: sensor.tekniktank_2
    style:
      top: 53%
      left: 42%
      font-size: 16px
      color: black
  - type: state-label
    entity: sensor.slavtank_2
    style:
      top: 53%
      left: 15%
      font-size: 16px
      color: black
  - type: state-label
    entity: sensor.tekniktank_3
    style:
      top: 74%
      left: 42%
      font-size: 16px
      color: black
  - type: state-label
    entity: sensor.slavtank_3
    style:
      top: 74%
      left: 15%
      font-size: 16px
      color: black
  - type: state-label
    entity: sensor.retur_radiator
    style:
      top: 10%
      left: 36%
      font-size: 16px
      color: darkblue
  - type: state-label
    entity: sensor.framledning_radiator
    style:
      top: 10%
      left: 21%
      font-size: 16px
      color: darkred
  - type: state-label
    entity: sensor.power_127
    style:
      top: 61%
      left: 72%
      font-size: 16px
      color: black
  - type: icon
    icon: mdi:flash
    style:
      top: 55%
      left: 72%
      font-size: 16px
      color: black
  - type: icon
    icon: mdi:fire-off
    style:
      top: 83%
      left: 72%
      font-size: 16px
      color: darkred
  - type: state-label
    entity: sensor.retur_radiator
    style:
      top: 10%
      left: 36%
      font-size: 16px
      color: blue
image: /local/vedpanna2.png

Here’s a template sensor I created to track the last time my cat came in or out.

template:
  - trigger:
      - platform: time_pattern
        minutes: "*"
    sensor:
      - name: katniss_since
        state: >
          {{ relative_time(strptime(state_attr('binary_sensor.pet_katniss', 'since'), '%Y-%m-%dT%H:%M:%S%z')) }}

FYI, that’s an ISO timestamp, you don’t need to use strptime with a format.

      - name: katniss_since
        state: >
          {{ relative_time(state_attr('binary_sensor.pet_katniss', 'since') | as_datetime) }}
1 Like

Thank you for your reply and for trying to help!

I struggle with this and try to create something, but I can’t get it right.

Can you think of how the code should look like in my case…? Given that the entity I wan’t to use for start/reset count is called sensor.power_127

Something like…?

template:
  - trigger:
      - platform: time_pattern
        minutes: "*"
    sensor: 
      - name: time_since_fire
      -sensor: sensor.power_127
        state: >150W
        {{ relative_time(state_attr('sensor.power_127', 'since') | as_datetime) }}

Gah, probably I’m totally off :roll_eyes:

Thank you for replying! You seem knowledgable! Do you think your info and example code will work for the purpose that i’m trying to achieve?