jayha
(jay)
July 12, 2017, 1:50am
1
Hi, i tried to follow the documentation for Sonos TTS using the below but it does not do anything…
please Help.
configurations.yaml has:
script:
# > SONOS TTS
say:
alias: SONOS TTS
sequence:
- service: media_player.sonos_snapshot
data_template:
entity_id: "{{ where }}"
- service: tts.google_say
data_template:
entity_id: "{{ where }}"
message: "{{ what }}"
# Add a delay in a length which you think fits best for all the things you want to say over TTS
- delay: '00:00:07'
- service: media_player.sonos_restore
data_template:
entity_id: "{{ where }}"
automations.yaml has:
- alias: test speaking'test'
trigger:
- platform: time
at: '21:41:00'
action:
- service: script.sonos_say
data:
sonos_entity: media_player.living_room
volume: 0.5
message: 'TTS test'
delay: '00:00:05'
thanks,
cgtobi
(Tobi)
July 12, 2017, 6:02am
2
Have a look at this thread to get an idea on how it can be implemented.
jayha
(jay)
July 12, 2017, 8:27pm
3
unfortunately for me thats where i copied the configs from…
cgtobi
(Tobi)
July 13, 2017, 5:31am
4
In the automation you are calling script.sonos_say
but your script actually is called say
. And you are not using where
and what
in your automation.
I recommend to try these as reference:
Hi guys, I’ve been fidling with this script to use my sonos system as you do. I’ve found a solution for the duration issue. The problem is: the expected format for the duration is HH:MM:SS but this script was sending H:M:S.
The main change is in the duration string formatting (HH:MM:SS):
{{ “%02i:%02i:%02i”|format(hours, minutes, seconds)}}
The full script below:
sonos_tts:
alias: Sonos Text To Speech
sequence:
- service: media_player.sonos_snapshot
data_template:
ent…
and
here you go. Please let me know if you need more.
configuration:
homeassistant:
name: Home
latitude: !secret home_latitude
longitude: !secret home_longitude
elevation: 21
unit_system: metric
time_zone: Europe/Brussels
customize: !include customize.yaml
tts:
- platform: google
cache: true
time_memory: 300
language: 'nl'
scriot:
sonos_tts:
alias: Sonos Text To Speech
sequence:
- service: media_player.sonos_snapshot
data_template:
entity_id: "{{ 'media_pla…
jayha
(jay)
July 19, 2017, 8:16pm
5
thanks, i am still working on getting this “Working”… been short on time.
jayha
(jay)
July 25, 2017, 8:04pm
6
it looks like my formatting is screwed up… i get the below error:
Jul 25 20:02:40 hassbian systemd[1]: Started Home Assistant for homeassistant.
Jul 25 20:02:45 hassbian hass[10517]: 2017-07-25 20:02:45 ERROR (Thread-1) [homeassistant.util.yaml] while parsing a block mapping
Jul 25 20:02:45 hassbian hass[10517]: in “/home/homeassistant/.homeassistant/scripts.yaml”, line 2, column 3
Jul 25 20:02:45 hassbian hass[10517]: expected , but found ‘-’
Jul 25 20:02:45 hassbian hass[10517]: in “/home/homeassistant/.homeassistant/scripts.yaml”, line 7, column 3
Jul 25 20:02:45 hassbian hass[10517]: 2017-07-25 20:02:45 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: while parsing a block mapping
Jul 25 20:02:45 hassbian hass[10517]: in “/home/homeassistant/.homeassistant/scripts.yaml”, line 2, column 3
Jul 25 20:02:45 hassbian hass[10517]: expected , but found ‘-’
Jul 25 20:02:45 hassbian hass[10517]: in “/home/homeassistant/.homeassistant/scripts.yaml”, line 7, column 3
Jul 25 20:02:45 hassbian hass[10517]: Config directory: /home/homeassistant/.homeassistant
cgtobi
(Tobi)
July 26, 2017, 5:09am
7
Well, if you’d paste that part of your config and use some propper markdown it would be easier to help you.
jayha
(jay)
July 26, 2017, 3:02pm
8
sure, it is a copy paste of what you had posted…
pi@hassbian:/home/homeassistant/.homeassistant $ cat scripts.yaml
sonos_tts:
sequence:
# alias: Sonos Text To Speech
- service: media_player.sonos_snapshot
data_template:
entity_id: "{{ 'media_player.' ~ where }}"
- service: tts.google_say
data_template:
entity_id: "{{ 'media_player.' ~ where }}"
message: "{{ what }}"
- delay:
seconds: 1
- delay: >-
{% set duration = states.media_player[where].attributes.media_duration %}
{% if duration > 0 %}
{% set duration = duration - 1 %}
{% endif %}
{% set seconds = duration % 60 %}
{% set minutes = (duration / 60)|int % 60 %}
{% set hours = (duration / 3600)|int %}
"{{ [hours, minutes, seconds]|join(':') }}"
- service: media_player.sonos_restore
data_template:
entity_id: "{{ 'media_player.' ~ where }}"
cgtobi
(Tobi)
July 26, 2017, 9:29pm
9
The formatting looks off a little.
Try this example: SONOS TTS Script
jayha
(jay)
July 27, 2017, 3:51am
10
thanks, that got past the errors… still not hearing anything from sonos…
when i look at the logbook, i do see the automation getting triggered.
test speaking has been triggered, after the switch being turned on.
heres what i have in my automations.yaml
- alias: test speaking
trigger:
platform: state
from: 'off'
to: 'on'
entity_id: switch.dinning_light_switch_2_0
action:
service: script.turn_on
entity_id: script.sonos_say
data:
variables:
where: 'media_player.living_room'
# volume: 0.5
what: 'this works'
#delay: 00:00:05
heres the scripts.yaml copy of the example from above just changed the entitiy id name:
pi@hassbian:/home/homeassistant/.homeassistant $ cat scripts.yaml
sonos_say:
alias: "Sonos TTS script"
sequence:
- service: media_player.sonos_snapshot
data_template:
entity_id: "{{ sonos_entity|default('media_player.living_room') }}"
- service: media_player.sonos_unjoin
data_template:
entity_id: "{{ sonos_entity|default('media_player.living_room') }}"
- service: media_player.volume_set
data_template:
entity_id: "{{ sonos_entity|default('media_player.living_room') }}"
volume_level: "{{ volume|default(0.5) }}"
- service: tts.google_say
data_template:
entity_id: "{{ sonos_entity|default('media_player.living_room') }}"
message: "{{ message }}"
- delay: "{{ delay|default('00:00:00') }}"
- wait_template: "{{ is_state(sonos_entity|default('media_player.living_room'), 'playing') }}"
timeout: '00:00:05'
- wait_template: "{{ not is_state(sonos_entity|default('media_player.living_room'), 'playing') }}"
timeout: '00:02:00'
- service: media_player.sonos_restore
data_template:
entity_id: "{{ sonos_entity|default('media_player.living_room') }}"
cgtobi
(Tobi)
July 27, 2017, 5:13am
11
Maybe let’s try something simpler first, like this:
- alias: test speaking
trigger:
platform: state
from: 'off'
to: 'on'
entity_id: switch.dinning_light_switch_2_0
action:
- service: media_player.sonos_snapshot
data_template:
entity_id: media_player.living_room
- service: tts.google_say
data_template:
entity_id: media_player.living_room
message: "This works now."
- delay: "00:00:{{ states.media_player.wohnzimmer.attributes.media_duration | int }}"
- service: media_player.sonos_restore
data_template:
entity_id: media_player.living_room
jayha
(jay)
July 27, 2017, 5:07pm
12
this works! thanks Tobi.
so what would the reason be for me to use the script ? I’ll try to go thru both line/line to see if i can identify the problem… or feel free to enlighten me.
cgtobi
(Tobi)
July 27, 2017, 9:57pm
13
The script wraps a lot of things and makes it reusable. I actually don’t use that script at the moment. Unfortunately I don’t know why it breaks. Maybe post in the other thread.
How would I implement this for each switch, repeat config?
cgtobi
(Tobi)
July 28, 2017, 7:33am
15
This is what the script is for. It wraps most of the stuff.
Ok, I guess the next step is trying to figure out using scripts.
Thanks.
So, I created the sonos script and it works with the automation.
Is there anyway to specify the switch/light entity_id like the player so that the automation triggers for all switches/lights?
“entity_id: “{{ ‘media_player.’ ~ where }}””
Hey, the automation’s run as configured, but throw the following error after each, any ideas?
2017-08-02 23:28:49 ERROR (MainThread) [homeassistant.components.tts] Can't write 48b4c312a17150ddfb23df9d2e8d278ae3fdbbff_en-us_250172662_amazon_polly.mp3