Ok, been pulling my hair out over this.
I have a REST API that returns the last time my backup script finished in Unix a timestamp. I would like to set up a card in HA that displays how long it’s been since that happened. I also have custom css in play to alert me when it’s been too long since a backup. I’ve tried putting the relative_time function in the lovelace config, as well as templates section of the configuration.yaml. I’ve also tried using the timestamp_local in both places for a less-than-ideal solution. Thus far, no-go. I have also tried implementing a few things from the Epic Timestamp thread, but nothing is sticking.
Here is what I have, currently:
Configuration.yaml
sensor:
- platform: rest
name: "Backup Status"
json_attributes:
- backupTimeStamp
resource: https://tools.blahblah.net/cgi/local_stats.pl?query=backup
timeout: 10
scan_interval: 10
value_template: 'OK'
- platform: template
sensors:
backuptimestamp:
friendly_name: 'backup_timestamp'
value_template: '{{ states.sensor.backup_status.attributes["backupTimeStamp"] }}'
entity_id: sensor.backup_timestamp
lovelace Entity Card Configuration:
entity: sensor.backuptimestamp
icon: 'hass:refresh'
name: Backup Timestamp
style: |
ha-card {
background: {% if states("sensor.backuptimestamp")| int + 604800 < as_timestamp(now()) %} #730101 {% else %} #017301 {% endif %};
}
type: entity
This is what I currently have displaying.
What am I missing?