Always used Node-Red thought about moving to native HA but unsure where to start

I thought I would give HA automations/scripts a go but really have no idea where I should do this and how to start.

I thought I would start with script but then saw in the GUI there is no conditions but in the documentation there are, this got me wondering if scripts is the right place.

I have provided a picture of a 2 simple flows I would like to migrate over to HA, a pointer on what should be a script and what should be an automation process would help a lot and if I should be looking at YAML to achieve it instead of the GUI.

From a very high level I was looking at the start of each process to be a Automation and the rest scripts (can I do split conditions in the same script?)

image

Both should be automations. Trigger on the event then use a choose action (based on the light state) to determine which sequence of actions to run. No scripts required.

https://www.home-assistant.io/docs/scripts/#choose-a-group-of-actions

1 Like

So Iā€™ll add them to the Automation, do you recommend YAML or try to stay in the GUI?
Not an easy question I know but I would like to align where HA might be heading.

If you feel you might do some more advanced automation using jinja templates sometime in the future it would be good to start getting a grasp of YAML. If you can do Node Red you can do this just as easily. However for the automations above the UI editor would be sufficient.

If you are going to have a go at the YAML version, post here if you need help or have questions. The above automations will be a good introduction.

Thanks Tom,
I had seen the Choose command in the GUI but always thought ā€œDefaultā€ would run after the other actions so I couldnā€™t see how this was a if/else until I read the docs a bit harder :slight_smile:

Ta

1 Like

Thanks Tom, those ones are completed, it can be weird what you think should be a breeze to set up then turns out to be a little harder than you thought.

Is this possible it a single automation
I have a push button switch that has triggers of ā€œlong pressā€ and ā€œlong press releaseā€. Iā€™m looking at if the switch is longed press keep decreasing the brightness of the lights until released. I thought I would be able to do it in a Until loop but it appears I canā€™t repeat until a new different trigger and instead only trigger on the existing automation Trigger IDs which doesnā€™t appear to be any good as if I also add the ā€œlong press releaseā€ as a trigger, when the automation triggers on the release it runs as a different instance of the automation.

Thinking for this one I might need to set up (1 or 2) automations that turn on and off a script that decreases the lights, does that make sense?

image

latest Yaml version

id: '1628102794007'
alias: test light decrease
description: ''
trigger:
  - device_id: 8621b4f2fce548a49da1d754a2c41bcb
    domain: zha
    platform: device
    type: remote_button_long_press
    subtype: button
    id: '1'
  - device_id: 8621b4f2fce548a49da1d754a2c41bcb
    domain: zha
    platform: device
    type: remote_button_long_release
    subtype: button
    id: '2'
condition: []
action:
  - repeat:
      until:
        - condition: trigger
          id: '2'
      sequence:
        - device_id: 3f7189b028a7f5b5007604f8ce44fa08
          domain: light
          entity_id: light.computer_room
          type: brightness_decrease
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
mode: single

What kind of remote-control are you using?

Instead of creating automations to process the deviceā€™s button events, looks through the Blueprints Exchange section and see if thereā€™s an existing blueprint for the device. Some of the better ones support things like long press, hold, etc.

Assuming thereā€™s a blueprint for your device, itā€™ll be pre-configured to handle the deviceā€™s events. All you need to do is indicate what you want each button event to do.

For example, hereā€™s one for the Ikea 5-button remote-control.

Even if you donā€™t want to use a blueprint, and prefer to create your own automation from scratch, you can examine how the blueprint is constructed and get ideas for your automation.

Hi 123, to answer your question there are all ready pre-configured commands for this switch ā€œlong pressā€ and ā€œreleaseā€ which I am using. The issue is that the release command isnā€™t cancelling the until loop I am in and hence the light turns off. The automation is in single mode so unsure why this isnā€™t happening.

I see my YAML was badly formatted yesterday so Iā€™ve reformatted it.

It wonā€™t because mode: single means while the automationā€™s action is executing (i.e. itā€™s busy doing the repeat) anything attempting to trigger it again (like when itā€™s second trigger detects remote_button_long_release) will be rejected. Your repeat is waiting to hear from something that is actively blocked from being heard. Check the Log and youā€™ll probably see a message about ā€˜already runningā€™ each time you released the button.

Try changing mode to restart. When you long_press, the repeat will begin iterating and the moment you release the button (triggering the second trigger: id = ā€˜2ā€™), the entire action session is terminated and a new session begins. This new session wonā€™t iterate repeat even once because untilā€™s condition will be satisfied. In other words, it will cease decreasing the lightā€™s brightness.

1 Like

Restart has worked, I miss understood the term single in this case. I thought single meant that it would not run any more instances of this automation and only execute against the current one (eg you only have one instance running).

Is did confuse me, with the description as I expected the triggers to be able to pass a message at any time to a running automation in a loop but see this issue the case.

Thanks 123

I see how you interpreted it and you were half right, thereā€™s only one instance running. However, while itā€™s running, the automationā€™s trigger section is, effectively, disabled and ignores attempts to trigger again. ā€œIā€™m busy servicing working on the previous request, try again later!ā€