Rule Machine not working as expected (line by line)

Why doesn't rule machine run in cyclic steps?

I would presume that every instruction is run in sequence. But it is not the case. For example if i have an instruction to set volume to x value, but wihout the wait instruction the speaker plays the music before the volume is set.

I can work with wait instruction but at the end that is not reliable.

I'm fairly sure RM doesn't complete each action in turn, that's just the way it is. You'll probably need to add waits if that's needed.

1 Like

Can't you just specify what volume you want to use in that part of the rule? You could also edit your MP3 (alarm_tone) to include a voice message. That would make for a much less complicated rule.

1 Like

I've managed to make it work with a global "rule running" variable that i set to false in another rule.
And no, it does not work if i set the volume and play the mp3. The file is played before the volume is properly set.
Also in the rule i capture the initial volume and restore it at the end.

Regarding rule machine, maybe it is a good ideea to change it to that mode.

What I meant was that you can set the volume at which you want to speak the alert:

In fact it's possible to select the specific voice and volume by using a string.

1 Like

You also don't seem to have your IFs and END-IFs properly formatted.

At least for me, the ā€œin-lineā€ volume command simply doesnā€™t work. See my post here:

That was the first thing i've tried. The obvious choice,
It just would not run as expected,
If i use speak on with volume at 70 only the text is played at that volume. The mp3 alarm file is played at initial volume even thought the instruction is ran later.

Setting an attribute with a Wait for Event on that attribute immediately after often fails due to timing issues. You can prevent that by adding a short delay (2 seconds?) to the Set Volume action so the wait has time to set up before the event is generated.

Also consider using Wait for Expression instead of Wait for Event, in case an event is not generated (e.g. the volume is already set to 70).

1 Like

Please detail.

In the picture attached i have:
IF
IF
END IF
ELSE

What is wrong with that?

It will work but it triggers our collective OCD :wink:

You are missing an ENDIF at the very end. There is no need for that last ELSE and Exit Rule.

3 Likes

All IF statements should be paired with one and only one ENDIF statement.

1 Like

You have a point there.

1 Like

The second nested IF is closed by the END-IF, the first IF is left open (should be closed by an END-IF as the very last line)

Perhaps it doesn't matter, because your rule has an "Exit rule" that would end the rule before getting to that END-IF. Just weird to see it unclosed.

You donā€™t need the exit rule command

2 Likes

Thank you for advice.

I've modified the if statements and also changed wait for event to wait for expression.

For the setVolume actions, good idea, however, you seem to have removed the timeout for the wait, was that intentional?

Again I recommend adding a delay on the setVolume command. Donā€™t add a new action, just set this parameter on the existing setVolume action.

image

For the status = stopped wait, the wait for event was probably better. There is no risk of a timing issue and you actually want a new event to complete the wait.

I've seen some situations where RM (or certain commands) can "queue up" some things. Until there's a lull in activity on the hub, those things can be deferred past where you'd expect. This can be an issue when you are setting things for other rules (e.g., PB, variables, etc.) if the hub is busy. When you run into that, something like a 1 second wait can give the hub a chance to get the other things done (it puts the running rule back at the "end of the line" it seems). The Hubitat folks can opine in more detail, this is just what I've found from time to time.

Hmm, that might be an issue. I've seen alerts saying the hub is very loaded.