Home Assistant Community

Output speech to Alexa based on state

#1

I’m a bit lost here to be honest.

Can anyone offer advise on how I can get my alexa devices (or a single device) to output speech based on a state? I’m thinking of something like “The washing is done” once the washing machine finishes or announcing my kids bed time, is this possible?

I’m quite new to node red but i’mm sure this is possible, just can’t quite work it out!

1 Like
#2

echo%20show

#3

I’d like to to this also, I’m guessing the ‘media_player.alexa_tts’ is a some assistant component? Do you have a link?

#4

Here’s my hokey morning alarm. You may find this useful:

- alias: 'Good Morning Richard'
  initial_state: true
  trigger:
  - at: '07:00:00'
    platform: time
  condition: []
  action:
# Light on dim
  - service: light.turn_on
    data:
      brightness: '80'
      entity_id: light.bedroom
# Moring greeting
  - service: media_player.volume_set
    data:
      entity_id: media_player.406_bedroom_echo_dot
      volume_level: 0.6
  - delay: '00:02'
  - service: media_player.play_media
    data:
      entity_id: media_player.406_bedroom_echo_dot
      media_content_id: Alexa.GoodMorning.Play
      media_content_type: sequence
# Weather report
  - delay: '00:02'
  - service: media_player.play_media
    data:
      entity_id: media_player.406_bedroom_echo_dot
      media_content_id: Alexa.Weather.Play
      media_content_type: sequence
# Coffee yet?
  - delay: '00:05'
  - service: notify.alexa_media
    data:
      target: media_player.406_bedroom_echo_dot
      message: Do you have your coffee yet?
      data:
        type: tts
1 Like
#5

Or this one to announce and take a picture when the tool shed door is opened:

- alias: 'Tool Shed Door Open'
  initial_state: true
  trigger:
  - entity_id: binary_sensor.tool_shed_opened
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - service: notify.alexa_media
    data:
      target: media_player.406_kitchen_echo
      message: The tool shed door has been opened
      data:
        type: tts
  - data:
      entity_id: camera.406_north
      filename: /config/camera_snapshots/opened {{ entity_id.entity_id }}_{{ now().strftime('%Y-%m-%d
        %H.%M.%S') }}.jpg
    service: camera.snapshot
#6

I managed it by installing the Alexa Media Player add on and then refreshing Node Red.

After that I was apple to call media_player.alexa_tts via a service call as @cyberumb15 illustrated above.

Turns out it was pretty easy!

#7

Thanks, this is just the sort of thing i’m trying to implement!

#8

Thanks very much for the link, I’ll have to try the media player addon.

I did try and get an Alexa remote working directly in NodeRED with this node:

but I could never get it to Authenticate my amazon account, but it is an early version

EDIT After installing the components and python module alexapy it seems to be working, very nice.

Right now I’ve got simple reminder that notifies me when homeassistant has booted up after tinkering with the config, you can use

  trigger:
    platform: homeassistant
    event: start

as the trigger, once I get some more creative uses I’ll have to add them :slight_smile:

#9
[{"id":"78d5451.c65f8bc","type":"switch","z":"40ebc6d9.fa1168","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":370,"y":200,"wires":[["9edcaab4.b8e6f8","447adc98.23e524","d6941896.b81638","7c6bba4c.ef8d64","79edea42.8a4884","b72d8775.355fa8","201c2f18.3eafb","c7e1b4fe.d48da8"],[]]},{"id":"9edcaab4.b8e6f8","type":"api-call-service","z":"40ebc6d9.fa1168","name":"ON - TV Power","server":"62d7bb2f.196044","service_domain":"switch","service":"turn_on","data":"{\"entity_id\":\" switch.sonoff_power\"}","mergecontext":"","x":780,"y":220,"wires":[[]],"outputLabels":["on"]},{"id":"447adc98.23e524","type":"api-call-service","z":"40ebc6d9.fa1168","name":"ON - Sound Bar","server":"62d7bb2f.196044","service_domain":"switch","service":"turn_on","data":"{\"entity_id\":\" switch.sound_bar\"}","mergecontext":"","x":780,"y":260,"wires":[[]],"outputLabels":["on"]},{"id":"d6941896.b81638","type":"api-call-service","z":"40ebc6d9.fa1168","name":"TV Blind Down","server":"62d7bb2f.196044","service_domain":"switch","service":"turn_on","data":"{\"entity_id\":\" switch.blind_1_down_up\"}","mergecontext":"","x":780,"y":300,"wires":[[]],"outputLabels":["on"]},{"id":"201c2f18.3eafb","type":"api-call-service","z":"40ebc6d9.fa1168","name":"ON - Side lamp","server":"62d7bb2f.196044","service_domain":"switch","service":"turn_on","data":"{\"entity_id\":\" switch.living_room_lamp\"}","mergecontext":"","x":780,"y":140,"wires":[[]],"outputLabels":["on"]},{"id":"c7e1b4fe.d48da8","type":"api-call-service","z":"40ebc6d9.fa1168","name":"ON - Side lamp 2","server":"62d7bb2f.196044","service_domain":"switch","service":"turn_on","data":"{\"entity_id\":\" switch.living_room_side_lamp\"}","mergecontext":"","x":790,"y":100,"wires":[[]],"outputLabels":["on"]},{"id":"8fc4f623.11e1c8","type":"api-call-service","z":"40ebc6d9.fa1168","name":"alexa voice","server":"62d7bb2f.196044","service_domain":"media_player","service":"alexa_tts","data":"{\"entity_id\":\"media_player.annaka_s_echo_dot\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":1050,"y":180,"wires":[[]]},{"id":"e8c928c6.370878","type":"comment","z":"40ebc6d9.fa1168","name":"Alexa turn movie time on","info":"","x":230,"y":140,"wires":[]},{"id":"7c6bba4c.ef8d64","type":"api-call-service","z":"40ebc6d9.fa1168","name":"Dinning room lamp","server":"62d7bb2f.196044","service_domain":"switch","service":"turn_off","data":"{\"entity_id\":\" switch.dinning_room\"}","mergecontext":"","x":790,"y":340,"wires":[[]],"outputLabels":["on"]},{"id":"4a1c5462.8047ac","type":"alexa-local","z":"40ebc6d9.fa1168","devicename":"movie time","inputtrigger":false,"x":190,"y":200,"wires":[["78d5451.c65f8bc"]]},{"id":"79edea42.8a4884","type":"api-call-service","z":"40ebc6d9.fa1168","name":"Computer lamp","server":"62d7bb2f.196044","service_domain":"switch","service":"turn_off","data":"{\"entity_id\":\" switch.computer_lamp\"}","mergecontext":"","x":780,"y":380,"wires":[[]],"outputLabels":["on"]},{"id":"b72d8775.355fa8","type":"function","z":"40ebc6d9.fa1168","name":"Alexa random messages","func":"msg.payload = {};\nmsg.payload.data = {};\nmsg.payload.data.entity_id = {};\nmsg.payload.data.message ={};\n\nvar myArray = [\n  \"The entertainment system has been primed, and is ready to go... Enjoy yourself, and don't forget the snacks \",\n  \"hey sunshine, go put your feet up and watch a good movie\",\n  \"Marmalade will hold the fort, you go and enjoy yourself\",\n  \"See ya soon\",\n  \"Go on then bugger off, I'll sit and mumble to myself\",\n  \"The entertainment system is all set up, go have fun\"\n];\n\nvar randomItem = myArray[Math.floor(Math.random()*myArray.length)];\n\nmsg.payload.data.entity_id = \"media_player.annaka_s_echo_dot\";\nmsg.payload.data.message = randomItem;\n\n\nreturn msg;\n","outputs":1,"noerr":0,"x":810,"y":180,"wires":[["8fc4f623.11e1c8"]]},{"id":"62d7bb2f.196044","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

Using Alexa to set up my movie room and say some randomn quotes as she does so.