totolino
(totolino)
December 7, 2018, 11:55am
1
Hi guys!
I have this intent
Rollladen:
speech:
type: plain
text: 'Okay, ich fahre den Rollladen {{ whichCover }} {{ actionType }}.'
action:
- service_template: {% if actionType == "runter" %}cover.close_cover{% elif actionType == "hoch" %}cover.open_cover{% endif %}
data_template:
entity_id: cover.{% if whichCover == "Ankleidezimmer" %}oeq1850763{% elif whichCover == "Schlafzimmer" %}peq0005525{% endif %}
but instead of cover.close_cover
it prints out cover.close/cover
Whats my mistake?
petro
(Petro)
December 7, 2018, 12:47pm
2
Thats not your problem. Your problem is that you don’t have your templates in quotes. Single line templates need quotes. Double line templates don’t. This should fix your real issue:
Rollladen:
speech:
type: plain
text: 'Okay, ich fahre den Rollladen {{ whichCover }} {{ actionType }}.'
action:
- service_template: "{% if actionType == 'runter' %}cover.close_cover{% elif actionType == 'hoch' %}cover.open_cover{% endif %}"
data_template:
entity_id: "cover.{% if whichCover == 'Ankleidezimmer' %}oeq1850763{% elif whichCover == 'Schlafzimmer' %}peq0005525{% endif %}"
You’re using if and else if only. You don’t really have a fallback plan for something other than ‘runter’, ‘hoch’, ‘Ankleidezimmer’, and ‘Schlafzimmer’.
You have a mishmash of capitals and lowercase. It would be safest to place all words in a single case.
With that being said, i’d recommend this:
Rollladen:
speech:
type: plain
text: 'Okay, ich fahre den Rollladen {{ whichCover }} {{ actionType }}.'
action:
- condition: template
value_template: "{{ actionType | lower in ['runter','hoch'] and whichCover | lower in ['ankleidezimmer','schlafzimmer'] }}"
- service_template: "{% if actionType | lower == 'runter' %}cover.close_cover{% elif actionType | lower == 'hoch' %}cover.open_cover{% endif %}"
data_template:
entity_id: "cover.{% if whichCover | lower == 'ankleidezimmer' %}oeq1850763{% elif whichCover | lower == 'schlafzimmer' %}peq0005525{% endif %}"
1 Like
totolino
(totolino)
December 7, 2018, 5:43pm
4
This works really well. Thank you. I have two more questions.
Where can i find documentation for this?
I have one more: Ankunftsort is my variable
Fahrdauer:
speech:
type: plain
text: Du fährst aktuell {{ states('sensor.{{ Ankunftsort }}') | round(0) } nach {{ states.sensor.{{ Ankunftsort }}.attributes.friendly_name }}. Am schnellsten bist du über {{ states.sensor.{{ Ankunftsort }}.attributes.route }}
petro
(Petro)
December 7, 2018, 5:49pm
5
You can’t encapsolate templates in templates. I.E {{}} or {%%} cannot be inside {{}} or {%%}.
Fahrdauer:
speech:
type: plain
text: >
{% set entity_id = 'sensor.'+Ankunftsort | lower %}
{% set duration = states(entity_id) | float | round(0) %}
{% set friendly_name = state_attr(entity_id, 'friendly_name') %}
{% set route = state_attr(entity_id, 'route') %}
Du fährst aktuell {{ duration }} nach {{ friendly_name }}. Am schnellsten bist du über {{ route }}
1 Like
totolino
(totolino)
December 7, 2018, 5:54pm
6
You are just awesome. Thank you!!!
totolino
(totolino)
December 11, 2018, 10:52am
7
Benzinpreis:
action:
- service: script.sonos_say
data_template:
sonos_entity: media_player.wohnzimmer
volume: 0.25
delay: '00:00:09'
message: >
{% set TankstellemitSorte = 'sensor.'+Tankstelle+'_'+Benzinsorte | lower %}
{{ Benzinsorte }} kostet aktuell {{ TankstellemitSorte }}.
sensor name: sensor.bft_e5
value: 1.419 (for example)
sonos is telling me the name of the variable “sensor.bft_e5”
petro
(Petro)
December 11, 2018, 2:46pm
8
You aren’t getting the state
action:
- service: script.sonos_say
data_template:
sonos_entity: media_player.wohnzimmer
volume: 0.25
delay: '00:00:09'
message: >
{% set TankstellemitSorte = 'sensor.'+Tankstelle+'_'+Benzinsorte | lower %}
{{ Benzinsorte }} kostet aktuell {{ states(TankstellemitSorte) }}.
1 Like
totolino
(totolino)
December 15, 2018, 8:02am
9
Hi. Thank you @petro . You really helped me a lot.
Right now i am struggeling here.
I made a scrape sensor which is getting the weather. the sensor is working fine
Wettervorhersage:
action:
- service: script.sonos_say
data_template:
sonos_entity: media_player.wohnzimmer
volume: 0.25
message: >
{% set createsensor = 'sensor.berlin_'+whichSensor+'_'+wannWetter | lower %}
{% set wettersensor = states(createsensor) %}
{{ wettersensor }}.
delay: '00:00:10'
In the frontend template tester i get the right text by entering:
{{ states.sensor.berlin_wetter_heute.state }}
In Berlin gibt es tagsüber einen wolkenlosen Himmel und die Temperaturen liegen zwischen -1 und 1°C. In der Nacht überwiegt dichte Bewölkung, aber es bleibt trocken und die Temperatur sinkt auf -2°C.
But even if i type in {{ states.sensor.berlin_wetter_heute.state }}
my speaker will say ‘unknown’
I also have a second question:
The text is sometimes longer than the maximum length of 255 letters. Is there a workaround?
petro
(Petro)
December 15, 2018, 11:15am
10
You’ll have to see why it says unknown. SOmething appears to be wrong with your scrape sensor.
You’d have to move to a platform that can handle it. A python script for example.