nabulke
(horst)
May 20, 2019, 12:31pm
1
I’ve got this example event set up, to show an notification on my tablet frontend (using tileboard):
Look like that on my tablet:
As you can see, the message does not appear as intended. What I’d like to see is the content of this variable (yellow marker in screenshot):
How can I add an attribute of the sensor state to the JSON message?
Thanks for any help!
krash
(Harry)
May 20, 2019, 12:40pm
2
You probably need to use {{states.sensor.**sensor-name**.state}}
to get the desired value parsed into a template.
There is a very usefull feature in HA to test these things out. It’s called Template editor and its found in the side bar under Developer tools.
Go there, delete the existing code and paste yours, see what the result is, and go from there.
Edit: the template editor has been now moved to Developer Tools - > Template editor tab
3 Likes
nabulke
(horst)
May 20, 2019, 12:50pm
3
It works in the template editor:
But unfortunately, if I use the same message format in the event:
{
"command": "notify",
"message": "{{states.sensor.dwd_weather_warnings_current_warning_level.attributes.warning_1_headline }}"
}
it still looks like that
krash
(Harry)
May 20, 2019, 12:53pm
4
Try removing the quotes?
{
"command": "notify",
"message": {{states.sensor.dwd_weather_warnings_current_warning_level.attributes.warning_1_headline }}
}
nabulke
(horst)
May 20, 2019, 12:54pm
5
Without quotes: Error parsing JSON: SyntaxError: JSON.parse: expected property name or '}' at line 3 column 17 of the JSON data
krash
(Harry)
May 20, 2019, 1:00pm
6
I dont know how tileboard notifications work,
Maybe you need to open another bracket in the json and give it some data_template
in order to parse the template data?
Here’s how my automations work with html5 notifications, maybe it’ll help you out:
...
action:
- data_template:
message: Stella has left the house {{ now().strftime('%H:%M')}}
title: Presence
service: notify.notify_html5
tom_l
May 20, 2019, 1:46pm
7
I don’t think the automation editor supports templates. You will have to write it in yaml.
nabulke
(horst)
May 20, 2019, 2:23pm
9
As far as I can see, I’m using the same syntax:
{
"command": "notify",
"message": "{{ states.sensor.dwd_weather_warnings_current_warning_level.state }}"
}
So it probably is a problem with the TileBoard component?
nabulke
(horst)
May 20, 2019, 6:49pm
10
I tried many different variations in YAML, without success.
e.g.:
action:
- event: tileboard
event_data:
command: notify
icon: mdi-weather-lightning-rainy
id: dwd_warnung
lifetime: '28800'
data_template:
message: 'State {{ states.sensor.dwd_weather_warnings_current_warning_level.state }}'
title: Wetterwarnung
type: warning
ErwinP
(Erwin)
May 21, 2019, 8:04am
11
For what it’s worth, here’s my (working) automation rule:
action:
- service: switch.turn_off
entity_id: switch.sonoff_*hidden*
- service: notify.debug
data:
message: "DEBUG ToTheLiving - Timer finished, lamp is going out again. Bowlamp: {{ states.switch.sonoff_*hidden*.state }}"
I’m using simplepush as a notification platform.
1 Like
jualfoar
(Julian)
April 1, 2020, 9:53pm
12
your var need to be like this!
{{ states(‘PUT_YOUR_ENTITY_HERE’) }}
Hope that you still looking for an anwser
5 Likes
Machtnix
(Nicolas Weiss)
March 18, 2021, 8:38am
13
Hello,
I’m new to this board and quite new to HASS, but I’m loving this system and loving this community, especially this thread, because now I found a way to monitor the tracker of my dog.
Have a nice day.
1 Like
As the answer is not here and I have been searching for it for hours you need to use this:
state_attr(‘sensor.livingroom’, ‘Battery numeric’)
So do not use states.
This worked for me! Thanks
I know your Question is Years old but hopefully this can help others too.
First you should check the Sensor in Developer Tools → States.
Then head over to Developer Tools → Template to play around.
Shows the State
{{ states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.state }}
Shows all Attributes
{{ states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes }}
Shows only one Attributes
{{ states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes.warning_1_headline }}
Now you can do something like this, it may look complicated but try to one value at the time
{{ states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes.warning_1_headline }} in {{ states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes.region_name }}. {{ states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes.warning_1_description }}
{% if as_timestamp(states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes.warning_1_start) | timestamp_custom('%Y-%m-%d') == now().strftime('%Y-%m-%d') %}
Von heute {{ as_timestamp(states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes.warning_1_start) | timestamp_custom('%I:%M') }} bis {{ as_timestamp(states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes.warning_1_end) | timestamp_custom('%I:%M') }}
{% else %}
Vom {{ as_timestamp(states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes.warning_1_start) | timestamp_custom('%I:%M (%d.%m)') }} bis {{ as_timestamp(states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes.warning_1_end) | timestamp_custom('%I:%M (%d.%m)') }}
{% endif %}
{% if states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes.warning_1_instruction != none %}
Es gibt folgende Hinweiße: {{ states.sensor.wetter_warnungen_kreis_garmisch_partenkirchen_current_warning_level.attributes.warning_1_instruction }}
{% endif %}
13 Likes
This is perfect. Thanks. Just what I needed to learn.
1 Like
JDv1
(Jd)
December 30, 2021, 5:43pm
19
Hi, that worked for my sensor too. But how do I learn this. Is there a guide for that? I’m other programming software you get suggestions when you type the dot. Will this come to HA as well?
I have been trying to do this for alexa notification where the text for the notification message comes from the value of a template sensor. After several attemps, finally the below worked for me. Hopefully can be of help to someone else trying to do the same:
service: notify.alexa_media_kannan_s_2nd_echo_dot_2
data:
data:
type: tts
message: "{{states(\"sensor.front_door_people_announce\")}}"
So you have to put the backslah before the quotes.