How do you trigger an automation by matching a string?
sensor.mystring == “123456” then trigger?
How do you trigger an automation by matching a string?
sensor.mystring == “123456” then trigger?
Using a state trigger.
trigger:
- platform: state
entity_id: sensor.downstairs_set_temperature
to: '123456'
Here is what I did.
id: '1645337245619'
alias: Tag 660
description: ''
trigger:
- platform: state
entity_id: sensor.uart_readline
to: '3510955660'
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.buzzer_on
mode: single
No joy yet. So how do I trouble shoot this? Is there a way to inspect the the string for carriage returns? Or am I just missing something?
Does developer tools confirm the sensor is returning a string and not a number?
I am guessing this is an ESPHome sensor based on the syntax.
As a tangent, you can also trigger and execute automations on the ESPHome device as well.
It has to change to that value. The automation won’t trigger if the sensor is already that value.
I’ve changed the value from valid to not valid and back.
How about this?
trigger:
- platform: template
value_template: "{{ '3510955660' in states('sensor.uart_readline') }}"
That worked. Thank you. Wonder why the other that could be made in the editor helper did not?
Thanks again.
I suspect you might be on to something with this reason:
I think, if you paste this in developer tools → template you should be able to see a carriage return (if that was the issue)
a{{ states('sensor.uart_readline') }}b
Cool … This was the result.
a3510955660b
Ascii 03 and Ascii 02 at the beginning.
Given that you already have an answer I suppose there is no need to clean the string?
True, no need to clean the string with that second method.
Is that why the first method failed and the second method found a string in a string?
This did not find the string acceptable.
trigger:
- platform: state
entity_id: sensor.uart_readline
to: '3510955660'
This did match even with the unreadable bytes.
trigger:
- platform: template
value_template: "{{ '3510955660' in states('sensor.uart_readline') }}"
Yes the first one asks if the string is exactly this, the second one says is this substring present in the string.
So the second method would also work if there was characters after the …5660
EOT (end of text) and SOT (start of text) characters. Are you clipping the end of a previous string?
a<EOT> <SOT>3510955660
Where does this come from?
It’s coming from a Chinese long range ISO18000-6C uhf rfid device. That must be the reason… to read high speed… It’s able to read crap loads of tags in succession.
Just for fun, try this:
{{ states('sensor.uart_readline') | slugify }}
Let me know if the result looks something like this (two leading underscores followed by the sensor’s value):
__3510955660
The purpose of slugify
is to convert a string to a slug (which is basically a string containing nothing but lowercase alphanumeric characters and all other characters are replaced by an underscore).
So I still have a valid string.
a{{ states('sensor.uart_readline') }}b
Result type: string
a3510955660b
then I use
{{ states('sensor.uart_readline') | slugify }}
and get
TemplateAssertionError: No filter named ‘slugify’.
That would be neat to see all the unreadables as underscores.
It appears that you are not using the latest release of Home Assistant. The slugify
filter is a recent addition.
Oh wow cool… Just haven’t had any super annoying problems to make me go to the latest version… Weighting out the possibility of breaking changes. lol
I’ll give it a try when I update. Thank you for responding !!
My 11 year old was looking at the new tablet mounted to the fridge and asked were is the clock? lol
I told him … well the home assistant guys don’t think that is something we should have as a standard card yet. I’ll work on it… hehe
I appreciate you guys !!