Hello fellow “domoters”!
I’m trying to send a variable to a Home Assistant script through IFTTT: I read the topics linked at the bottom of this post, but I’m still not able to do it.
What I’m trying to do is to receive the number of the channel from Google Home, and make Home Assistant cast the channel URL to a Chromecast.
This is my code and my IFTTT configuration:
change_kitchen_channel:
alias: "Change kitchen channel"
sequence:
- service: media_player.play_media
data_template:
entity_id: media_player.kitchen
media_content_id: >
{% if is_state("{{channel}}", "1") %} http://iptv/link/1
{% elif is_state("{{channel}}", "2") %} http://iptv/link/2
{% endif %}
media_content_type: video
I also tried with {{data.channel}} to indicate that’s a variable. The URLs are dummy ones, but the real ones arefully supported by HA and Chromecast (tried casting them with other scripts).
The URL is correct, because I’m using it to call other scripts. Has anybody got any suggestion?
Hi,
I want to make a call from an external program to Hass to send a photo using Telegram. The photo file name is different every time, so I’ve created an script and I want to call it passing the photo name as a variable:
I want to do this using a script because I want to add some logit to it, so I cannot call the notify/telegram service directly.
I’ve created the follwing simple script:
test:
alias: 'Test script'
sequence:
- service: notify.telegram
data_template:
…
I’m trying to make an automation which turns on (or adjusts) my office lights with a brightness based on the detected luminance. My automation is written as follows:
- alias: "Turn on lights when dark while working"
trigger:
- platform: state
entity_id: sensor.office_multi_luminance_3
- platform: numeric_state
entity_id: sensor.laptop_work_david
above: 500
condition:
condition: and
conditions:
- condition: state
entity_id: switch.turn_on_light…
home-assistant:dev
← home-assistant:service-parameters
opened 12:00AM - 22 Apr 16 UTC
Just cooked this up on the flight San Diego - Toronto ;-)
- Extracts scripts log… ic into a script helper
- Scripts now accept variables to be passed in when turned on via service.
- Automation: Add a trigger variable that is available to templates when processing action part.
- Automation: Allow using script sequence syntax for action
- Alexa: allow script syntax for action and expose intent slots as variables
- Script - Breaking: no longer allow config delay workaround by @jaharkes because it confused the code. (now using config validation to convert all to timedeltas)
``` yaml
automation:
trigger:
platform: mqtt
topic: some/notify/topic
action:
service: notify.notify
data_template:
message: {{ trigger.payload }}
automation 2:
trigger:
platform: state
entity_id: light.hue
action:
service: notify.notify
data_template:
message: {{ trigger.to_state.name }} is now {{ trigger.to_state.state }}
```
Available trigger data per platform:
``` python
'trigger': {
'platform': 'event',
'event': event,
}
'trigger': {
'platform': 'mqtt',
'topic': msg_topic,
'payload': msg_payload,
'qos': qos,
}
'trigger': {
'platform': 'numeric_state',
'entity_id': entity_id,
'below': below,
'above': above,
'from_state': from_state,
'from_value': from_value,
'to_state': to_state,
'to_value': to_value,
}
'trigger': {
'platform': 'state',
'entity_id': entity,
'from_state': from_s,
'to_state': to_s,
'for': time_delta,
}
'trigger': {
'platform': 'sun',
'event': event,
'offset': offset,
}
'trigger': {
'platform': 'template',
'entity_id': entity_id,
'from_state': from_s,
'to_state': to_s,
}
'trigger': {
'platform': 'time',
'now': now,
}
'trigger': {
'platform': 'zone',
'entity_id': entity,
'from_state': from_s,
'to_state': to_s,
'zone': zone_state,
}
```
https://www.reddit.com/r/homeassistant/comments/6f1ula/ifttt_hass_python_script_with_a_variable/
Have you checked your Jinja2 template code in the developer tools to see if it outputs the correct media_content_id?
Thanks to your help, I managed to “debug” the code!
First of all, the URL in IFTTT was incorrect: the correct one was http://url :port/api/services/script/change_kitchen_channel?api_password=pass, and not http://url :port/api/services/script/turn_on?api_password=pass (even if, with scripts that don’t need variables, this URL works).
Now the code:
change_kitchen_channel:
alias: "Change kitchen channel"
sequence:
- service: media_player.play_media
data_template:
entity_id: media_player.kitchen
media_content_id: >
{% if (channel == "1") %}
http://iptv/link/1
{% elif (channel == "2") %}
http://iptv/link/1
{% endif %}
media_content_type: video
1 Like