I have a setup with 2 sensors:
- raw: an MQTT sensor that is receiving JSON data from a topic and setting attributes accordingly
- processed: a template sensor that is massaging the raw data and formatting it in a more desirable way
I want ‘processed’ to be able to filter out (skip events) where a attribute does not match a particular condition. Is there an easy way to do this?
this is the code is setup
- platform: mqtt
name: "zkteco_raw"
state_topic: "zkteco/db_to_mqtt"
json_attributes_topic: "zkteco/db_to_mqtt"
value_template: "{{ value_json.id }}" # each event has a unique id. Used here to trigger state transitions
icon: mdi:door
- platform: template
sensors:
zkteco_cleaning:
value_template: "{{states('sensor.zkteco_raw')}}"
attribute_templates:
event_date: "{{ strptime(state_attr('sensor.zkteco_raw', 'event_time'), '%Y-%m-%d %H:%M:%S').date().isoformat() }}"
event_time: "{{ strptime(state_attr('sensor.zkteco_raw', 'event_time'), '%Y-%m-%d %H:%M:%S').time().isoformat() }}"
reader: "{{ state_attr('sensor.zkteco_raw', 'reader_name') }}"
name: "{{ state_attr('sensor.zkteco_raw', 'name') if state_attr('sensor.zkteco_raw', 'name').lower().startswith('cleaning') else 'private' }}"
wold be cool if any one has a tip