Wait between action steps

Guys, I’m not talking about reboots, or restarts of the program itself (I don’t believe that was ever a question of mine).

It was indicated to me, in this thread that whenever certain work is done inside HA, the system performs a “global reset”. HomeSeer simply does not do this.

Not technically “global”.

it only resets the parts you are working on.

if you save an automation in UI it reloads all automations and all running automations are reset/cancelled.

but running scripts and timers are unaffected.

if you save a script then scripts are cancelled but automations aren’t affected.

if you reload timers it resets timers but not scripts or automations…etc.

That is not what is happening in my case. I can see when the speaker wakes up via an indicator led (When it is sent audio or tts) . It follows that delay.

If I set the delay for 05 seconds, the audio file is not send for at least 5 seconds.

If I set the delay for 30 seconds, the audio file is not send for at least 30 seconds.

The first action is the sending of the audio file.

that’s definitely not the way it’s supposed to work so there has to be something else going on in your specific system.

try to remove the last action after the delay and see what happens.

action:
  - service: media_player.play_media
    data:
      media_content_id: http://192.168.1.132/media/music/20Hz1Sec.mp3
      media_content_type: music
    target:
      entity_id: media_player.house_audio_group
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0

the initial tone should start right away and then then the automation should continue to indicate it’s still running for the additional 5 seconds of the delay.

I’ll report back tonight.

Thank You for your help.

1 Like

Just to confirm, you’re saying the 20Hz tone only plays after the delay has expired (followed immediately by the TTS message)? Or does the tone never play, just the TTS message?

If it’s the former then that’s odd behavior because actions are normally executed in their defined order so the tone ought to come before the delay. :thinking:

That is how it works in every case.

This is not true. The speaker doesn’t wake up for five seconds, sure, but the service call to send the audio file was made before the delay. This is an indication that there is something wrong with your attempt to wake the speaker with the audio file, not that the service call isn’t being made. The speaker is not waking until the TTS command makes it through.

Have you checked for any errors with the service call? Have you ensured that the file is accessible and being played successfully?

1 Like

That’s why I suggested removing the tts and just use the audio file to see if it still “wakes up” after the delay or never.

1 Like

You guys nailed it. and @r-j-taylor you nailed every part of the problem.

I removed everything after the audio file and as you guys suspected, nothing played. no errors in logs that I can determine.

So I tried “http://192.168.1.132:8123/media/music/20Hz1Sec.mp3” in a browser and I get

401: Unauthorized.

I can play files from inside HA via left menu item Media Browser media > music > click on the file and it plays.

If I dump the file inside the root ‘media’ folder I get: (http://192.168.1.132:8123/media/20Hz4Sec.mp3)

Error 404 Not Found

Man, should it be this hard?

To be accessible from outside of HA, it should be in the www directory and accessed through a URL closer to http://192.168.1.132:8123/local/music/20Hz4Sec.mp3.

Doesn’t media_player.play_media have access to HA’s media directory?

I followed this as best I know how, but still no access via web browser or play via media_player.play_media.

2021-12-03_15-40-21

Well, I was explaining why you were getting errors when trying to access the files via a web browser. I can’t speak as well to Media Source as I’ve never used it, but your service call doesn’t follow the example from the docs you shared. If it did, it would look more like this:

media_content_id: "media-source://media_source/local/music/20Hz1Sec.mp3"

or

media_content_id: "media-source://media_source/music/20Hz1Sec.mp3"

Again, I haven’t used Media Source, so someone else may come along and correct me, but that’s my best guess.

So after several hours burned on this issue. I have found a ‘solution’, as there is a failure of some nature paying an audio files with media_player.play_media from the default ‘media’ folder when your HA instance is without ssl. (I’m using HA’s cloud)

I want to thank everyone who helped me, it was with all your suggestions that enabled me to get to the bottom of this issue (don’t think this basic function should have been a problem, but I digress. :thinking:)

Hope this help some in the future…

  1. Used the \config\www\ folder to place my audio in. Thanks @r-j-taylor

      example: `\\192.168.1.132\config\www\<media>\<music>`
    
  2. added the following to my configuration.yaml (for easier access)

homeassistant:
  media_dirs:
    media: "/config/www/media"
  1. Use the following structure for media_player.play_media

1 Like

This thread now serves as an example of how not to report a problem.

Instead of simply stating the tone failed to play but the TTS message did after the delay expired, it reported:

Anyone who has used Home Assistant for awhile knows that’s nonsense; a delay has no affect on actions preceding it.

The first post also gave the misleading impression that the tone did play:

Yet it never did play because Home Assistant was improperly configured to play local media.

Finally, the Solution post allegedly provides instructions for correcting the cause of the tone’s failure to play (for which delay was blameless) yet it overlooks to follow the instructions found in Media Source.

Any reader wishing to avoid these mistakes should read:
How to help us help you - or How to ask a good question.

2 Likes

Well as it turns out I did indeed follow much of the ‘How to help us help you’ list.

0-1-2-3-4) I have spent more hours reading and re-reading over and over again, watching help video’s and working on it before ever starting this post.

5-6) I didn’t follow

  1. I personally thought the title of this post was clear.

  2. I stated the goal first and not the problem and I thought I was clear when I said “Appears”…

9-11) I showed my automation, I believe properly formatted. Yes I didn’t understand the root cause, but isn’t that part of learning from the failures in your understanding and logic? “You don’t know what you don’t know” kind of thing.

  1. I failed to do, as at the time I didn’t think it was relevant in this case.

An observation over the 2 months of reading the posts and reply’s on this site is that most people here are extremely helpful, willing and able to help those who are new and simply don’t have the programming background required to accomplish many tasks in HA.

Then there are a few others, mostly HA veterans who fail to understand, either via hubris or repetition (the "get off my lawn type) that many, like my self are not programmers (hobby or professional) and thus when we read the documents some of it doesn’t make sense no matter how much we re-read.

In this specific case I read that section quite a few times (and many others), with no success (albeit due to a lack of knowledge and understanding on my part)

Thankfully @r-j-taylor and @finity could see through the noise of my ignorance and provide useful and meaningful steps to help me solve the problem at hand and more importantly help me gain knowledge and understanding of how HA works.

Lots of words there to excuse the failure to summarize a simple problem: tone didn’t play but delay and TTS worked.

Hours of reading and programming experience aren’t prerequisites for making a clear and simple observation.

  • Turned key, heard starter, but engine didn’t start.
  • Pressed remote, garage door didn’t close but lights flashed.
  • Refrigerator runs constantly and freezer is sub-zero but fridge section is warm.

Just to add -
this would have been MUCH easier to diagnose - had “show trace” been clicked, and the results posted here. At the very minimum, we would know from the timestamps that the automation did indeed run in the expected way.

Additionally to answer this:

That would be unaffected by editing the automations, provided that they were automation triggers, because it’s the core state system that keeps track of how long things have been in a certain state, the only thing that would throw that off, would be an actual restart of core.

But if you had an automation with a trigger of no motion detected for 10 minutes, that would still fire when the automations were reloaded, once there had been no motion for 10 minutes. So if you reloaded the automations 9 minutes after motion was last detected - it would still trigger a minute later.

Indeed, however yet another piece of the HA puzzle I was not aware of until yesterday. It is a VERY nice feature in which I’ve already used to diag. another issue.

1 Like

Thank you. So if I’m understanding you correctly. If I’m working on (updating) an automation and I hit the save button, the trigger will still be valid?

It is indeed very handy. Especially when you start passing variables to scripts. Eg - I have a LUX sensor outdoors, which I use to set a master slider to a value between 0% and 100% and all the rooms use the value of the master slider to determine the current level that any lights that are on should be set to:

service: input_number.set_value
target:
  entity_id: input_number.master_brightness_based_on_lux
data:
  value: >-
    {% set val = trigger.to_state.state|int %} {% set min_in = 1 %} {% set
    max_in = 3000 %} {% set max_out = 100 %} {% set min_out = 1 %} {% set out =
    (101 -  (max_out + (min_out - max_out) * (1 - ((val - min_in) / (max_in -
    min_in))))) %} {% if out < min_out %}{% set out = min_out %}{% endif %} {%
    if out > max_out %} {% set out = max_out %}{% endif %} {{ out|int }}

and then say the Livingroom is triggered when the value of the master changes - so it can determine it’s brightness level:

service: input_number.set_value
target:
  entity_id: input_number.livingroom_light
data_template:
  value: ' {% set min = 15 %} {% set max = 82 %} {% set b = (trigger.to_state.state|int) -(100 - max) %} {% if b <= min %} {% set v = min %} {% elif b >= max %} {% set v = max %} {% else %} {% set v = b %} {% endif %} {{ v }}'

The traces let me see the actual numbers being passed to automations and service calls so I can make sure it is working as I expect it to.

1 Like