Hi Guys and Gals,
I have a RFID reader all working and showing the states of each tag with a input_boolean
, simple
- input_boolean.rfid_tag1
- input_boolean.rfid_tag2
- input_boolean.rfid_tag3
so I now need a email report at the end of the day of each tag with the columns:
- Tag name
- Time On
- Time Off
the email is not a problem:
- service: notify.email_info
data:
title: "Tag - Daily Summary"
message: "Tag - Daily Summary"
data:
html: >
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
...
so, within the html
section above I have this (formatted to work in Developer Tools/Template)
{% set tag_name = states['input_boolean']
| rejectattr('entity_id.14', 'ne', 'r')
| rejectattr('entity_id.15', 'ne', 'f')
| rejectattr('entity_id.16', 'ne', 'i')
| rejectattr('entity_id.17', 'ne', 'd')
| sort(attribute = 'last_changed', reverse=true)
| map(attribute = 'object_id')
| list
| join(',')
%}
{% set tag_name_split = tag_name.split(',') %}
0/ {{ tag_name_split -}}
{% for i in range(0, tag_name_split | count) -%}
{% set col1 = states['input_boolean.' + tag_name_split[i]].name -%}
{% set col2 = '???' -%}
{% set col3 = '???' %}
1/ {{ col1 }}
2/ {{ col2 }}
3/ {{ col3 }}
{%- endfor %}
The problem:
- Cannot get the timestamp of the DB entry
- Cannot return more than just the last entry
what I have ended up doing, is adding two input_datetime entities get updated:
- input_boolean.rfid_tag1
- input_datetime.rfid_tag1_in
- input_datetime.rfid_tag1_out
- input_boolean.rfid_tag2
- input_datetime.rfid_tag2_in
- input_datetime.rfid_tag2_out
- input_boolean.rfid_tag3
- input_datetime.rfid_tag3_in
- input_datetime.rfid_tag3_out
{% set tag_name = states['input_boolean']
| rejectattr('entity_id.14', 'ne', 'r')
| rejectattr('entity_id.15', 'ne', 'f')
| rejectattr('entity_id.16', 'ne', 'i')
| rejectattr('entity_id.17', 'ne', 'd')
| sort(attribute = 'last_changed', reverse=true)
| map(attribute = 'object_id')
| list
| join(',')
%}
{% set tag_name_split = tag_name.split(',') %}
0/ {{ tag_name_split -}}
{% for i in range(0, tag_name_split | count) -%}
{% set col1 = states['input_boolean.' + tag_name_split[i]].name -%}
{% set col2 = states['input_datetime.' + tag_name_split[i] + '_in'].state -%}
{% set col3 = states['input_datetime.' + tag_name_split[i] + '_out'].state %}
1/ {{ col1 }}
2/ {{ col2 }}
3/ {{ col3 }}
{%- endfor %}
Now, while this is working there really must be a better way?
- To select the entity_id, with a wildcard. (i have seen some OLD threads on this issue, with no decent resolve)
- To do this without helper entities, as the data is in the database I just need to be able to get at it.
- And then moving on from this need to calculate time on in a day, week and month from the database data
Thanks for any help.