hassio-addons icon indicating copy to clipboard operation
hassio-addons copied to clipboard

U can broadcast to 1 device now.

Open malosaa opened this issue 2 years ago • 11 comments

It is now possible to broadcast to 1 device.

Today i did find out how, i did say hey google, broadcast/announce to kitchen. than it asked what message and it announcec only there.

But on my phone i could use a text message so the default voice speaks instead of the tts from home assistant.

Can you implement this ?

malosaa avatar Apr 03 '22 10:04 malosaa

just change your broadcast message to be "to kitchen the rest of your message"

chelming avatar Apr 12 '22 19:04 chelming

malosaa avatar Apr 13 '22 09:04 malosaa

@chelming

how does it work?

malosaa avatar Apr 13 '22 09:04 malosaa

Unfortunately, the package runs sequentially though. So while you can broadcast to one speaker, if you call those in a loop to target say 3 of them, each appears to run sequentially and takes between 3-4 seconds before moving to the next speaker. It would be nice to fork the command to execute immediately without waiting. This isn't an automation problem (I use script.turn_on and can also recreate it from simple curl GETs)

calisro avatar May 09 '22 14:05 calisro

@malosaa the broadcast command isn't actually broadcasting, it's running the command "broadcast ${your message here}" so if you just change your message to "to the kitchen it's time for bed" it'll actually run "broadcast to the kitchen it's time for bed".

@calisro does google have the ability to target a specified set of speakers when using your voice? like "broadcast to kitchen and livingroom it's lunch time"?

chelming avatar May 09 '22 14:05 chelming

@calisro does google have the ability to target a specified set of speakers when using your voice? like "broadcast to kitchen and livingroom it's lunch time"?

No. You can hit only one at a time with a targeted 'broadcast to '. It would be nice if the package would allow parallel commands to run so that we can do that in a loop. Although I do that now, it will be sequential and very delayed across multiple speakers.

            sequence:
              - variables:
                  speakers: |
                      {{ expand(target) | map(attribute='entity_id') | list }}
              - repeat:
                  count: '{{ speakers | count }}'
                  sequence:
                    - variables:
                        speaker: '{{ speakers[repeat.index - 1] }}'
                    - choose:
                        - conditions:
                            - condition: template
                              value_template: '{{ message | length > 0 }}'
                          sequence:
                            - service: script.turn_on
                              data:
                                variables:
                                  message: >-
                                    broadcast to {{ state_attr('' ~
                                    speaker,'friendly_name') }},
                                    {{message|default('Test Message',true) }}
                              target:
                                entity_id: script.run_ga_command

I wish google would just allow broadcasts to speaker groups but that isn't available either.

calisro avatar May 09 '22 14:05 calisro

@malosaa the broadcast command isn't actually broadcasting, it's running the command "broadcast ${your message here}" so if you just change your message to "to the kitchen it's time for bed" it'll actually run "broadcast to the kitchen it's time for bed".

In reality, the ga_command and the ga_broadcast is exactly the same and personally i don't even bother with the broadcast one. The command is simpler and not even sure why the second command was added only to prepend the message with 'broadcast'.

class BroadcastMessage(Resource):
    def get(self):
        message = request.args.get('message', default = 'This is a test!')
        text_query = 'broadcast '+message
        response_text, response_html = assistant.assist(text_query=text_query)
        logging.debug(response_text)
        return {'status': 'OK'}

api.add_resource(BroadcastMessage, '/broadcast_message')

class Command(Resource):
    def get(self):
        message = request.args.get('message', default = 'This is a test!')
        response_text, response_html = assistant.assist(text_query=message)
        logging.debug(response_text)
        return {'status': 'OK'}

api.add_resource(Command, '/command')

To me it just adds confusion and an extra notify config in HA for zero advantage. shrugs

calisro avatar May 09 '22 15:05 calisro

well they're not exactly the same because broadcast prepends the message with "broadcast". I think the idea was to make it slightly shorter e.g., /broadcast "it's time for lunch" vs /command "broadcast it's time for lunch" and you could reuse the message for other notification platforms.

chelming avatar May 09 '22 15:05 chelming

well they're not exactly the same because broadcast prepends the message with "broadcast". I think the idea was to make it slightly shorter e.g., /broadcast "it's time for lunch" vs /command "broadcast it's time for lunch" and you could reuse the message for other notification platforms.

Its actually the same length. :)

The actual commands need to run each are (the doc is wrong, you need "message="):

http://[your.hassio.IP]:5000/broadcast_message?message=its time for lunch
http://[your.hassio.IP]:5000/command?message=broadcast its time for lunch

But yes I know the 'idea' but it's just confusing a simple thing. I'm guessing the broadcast was published first and then command was added and it was retained for backward compatibility as its missing in this initial commit.

https://github.com/AndBobsYourUncle/hassio-addons/commit/9d8fa350e3784579695484bac02a40994ed684c7

calisro avatar May 09 '22 17:05 calisro

I use it now for all my notifications and it works as expected

malosaa avatar Jun 01 '22 06:06 malosaa

delete

calisro avatar Jun 01 '22 11:06 calisro