Need a correction or an advice

Hello,

I actually migrating my jeedom to home assistant.

I made automations and i would like to know if i did the right thing.

For the first, the differents steps are:
1 - At 11:00, i start this automation
2 - I check the color of the day
3 - if color is red, i am waiting 11h more and then i switch the tank to ON
4 - if color is different, i start immediatelly the switch the tank to ON

alias: Démarrage Ballon Eau Chaude
description: ""
trigger:
  - platform: time
    at: "11:00:00"
condition: []
action:
  - if:
      - condition: state
        entity_id: sensor.rte_tempo_couleur_actuelle
        state: Rouge
    then:
      - delay:
          hours: 11
          minutes: 0
          seconds: 0
          milliseconds: 0
      - type: turn_on
        device_id: d7564e916ab032faf5d7e5e6a30a7b25
        entity_id: 05922899de9e354b16dc0d0b7b209dec
        domain: switch
    else:
      - type: turn_on
        device_id: d7564e916ab032faf5d7e5e6a30a7b25
        entity_id: 05922899de9e354b16dc0d0b7b209dec
        domain: switch
mode: single

For the second:
1 - When the previous automation is executed, i start this one.
2 - I am waiting 30 minutes
3 - I repeat the action “check de sensor” until is status change
4 - If the status is changed since 30 minutes, i stop the tank’s switch

alias: Arrêt Ballon Eau Chaude
description: ""
trigger:
  - platform: state
    entity_id:
      - automation.demarrage_ballon_eau_chaude
    attribute: last_triggered
condition: []
action:
  - delay:
      hours: 0
      minutes: 30
      seconds: 0
      milliseconds: 0
  - repeat:
      until:
        - condition: state
          entity_id: binary_sensor.capteur_seuil_chauffe_eau
          state: "off"
          for:
            hours: 30
            minutes: 0
            seconds: 0
      sequence:
        - type: turn_off
          device_id: d7564e916ab032faf5d7e5e6a30a7b25
          entity_id: 05922899de9e354b16dc0d0b7b209dec
          domain: switch
mode: single

Bonus question:
The instruction “delay” will not block all others kind of instructions?

In your first automation, it isn’t a good idea to include a long delay like that. The state of the entities involved may change in the interim and a restart would stop the whole automation. A simpler approach would be to start a timer and have another automation fire when it reaches zero. Timers can be set to resume after a restart.

Also, in the action can’t you use the service switch.turn_on with the entity name of the switch? Device ids are best avoided if possible.

In the second automation, isn’t the trigger binary_sensor.capteur_seuil_chauffe_eau being turned on? Perhaps I’ve misunderstood it.

Edit: I’m not sure if daisychaining automations together like this is even possible, but I’m sure it’s a bad idea with unpredictable results - they’re supposed to respond to events in the system.

Also, in the action can’t you use the service switch.turn_on with the entity name of the switch? Device ids are best avoided if possible.

Ok, i don’t write it, i use the gui to make it. Home Assistant translate with the id. I will correct this.

In your first automation, it isn’t a good idea to include a long delay like that. The state of the entities involved may change in the interim and a restart would stop the whole automation. A simpler approach would be to start a timer and have another automation fire when it reaches zero. Timers can be set to resume after a restart.

To be sure, if i reboot HA, it will automatically pause and resume?

It will if you tick the restore box when creating the helper.

Edit: The problem with device ids is down the road a bit - if you ever have to replace a device, you will have to edit every automation and script it appears in to put in a new id. If you use entity names, you only have to give the new device the same name as the old one and everything will go on as before.

Another edit: I use the GUI too. In the action section you need to select “call a service”, then “switch.turn_on” and choose the name of your entity.

Out of curiosity, did you design these automations using the same programming logic as you would have in Jeedom?

The reason why I am asking is because the design of these automations is unlike anything one would normally do in Home Assistant.

If I may throw in a different approach, not using timers or delays at all… :slight_smile:

Automations:

  1. At 11:00 in the morning you simply set a template sensor with the color value for the day.
  2. If the template sensor is red, this triggers the automation to switch on.
  3. At 22:00 you simply check the value of the template sensor and react on it.
  4. Your second automation can be run at 11:30, and if I understand what it is doing, this can be put in here as well.

As you are doing things depending on the exact time of the day, it should not need any delays or timers, as you would use a time trigger at a specific time and check at that point what the circumstances are.

To avoid some nerve-wrecking along the road, you might want to post some of your automations to let them check by the community. Just in case. :slight_smile: :+1:

1 Like

The jeedom automation is different because when i created, i did’nt need to check the color of the day.

The logic of the first automation is:

  • start at 11:00
  • after 30 minutes, i check the power consumption. Until it is less than 50w and minimum of 2 hours after automation started, i turn off the tank.
    (that means, the water is hot and tank is off but not the “Controlled Mechanical Ventilation”).

Yeah, it is a good idea.

2 differents automation to start the tank.

Your second automation can be run at 11:30, and if I understand what it is doing, this can be put in here as well.

I will check if i can activate the last automation when the first part was played.

I made this:

alias: Démarrage Ballon Eau Chaude
description: ""
trigger:
  - platform: time
    at: "11:00:00"
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.rte_tempo_couleur_actuelle
        state: Rouge
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.contact_ballon
mode: single

like say @ Stiltjack, i modified the id by the name. Thank for the way to do that, i never found it alone.

I think my explanations were wrong

At 11:00, start tank only if days != red, else start it at 22:00
regardless of start time (11:00 or 22:00), wait 30 minutes and check power consumption and then stop it if power less 50W after 30 minutes.

PS: If i understand, you say, i can have only one automation for all of these steps. But i don’t understand how.

I recommend you consider implementing paddy0174’s suggestion. It leverages Home Assistant’s strengths. It can be implemented with a Trigger-based Binary Template Sensor and a single automation. It doesn’t use long delays, thereby reducing its vulnerability to restarts.

1 Like

I will work on this idea but not sure to understand the steps to do the same but all in one.

It’s possible to create a single automation to implement your application but it isn’t necessary. You’re free to create multiple automations, each handling a specific part of your overall application.