How to copy ui automations from one installation to another (incl device_id)

hi there,

Im starting a new home assistant installation because my old installation is becomming too unorganized.

But I dont want to do everything from scratch so of couse I want to copy elements from my old installation to the new one.

THE PROBLEM:
If i copy an automation from my old install to the new one it does not work. If I make an automation in the new installation i get a different device_id for my switch (switch.k_ikea)

automation.yaml for my old install:

- id: '1649230104669'
  alias: 'Box2: toggle k_ikea'
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.esp22_b7_gpio14
    to: 'on'
  condition: []
  action:
  - type: toggle
    device_id: d4fb55321b27895cddd1ba57ee026617
    entity_id: switch.k_ikea
    domain: switch
  mode: single

same automation in the new installation (via ui) gets a different device_id
automation.yaml for new install:

- id: '1649228719070'
  alias: 'Box2: toggle k_ikea'
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.esp22_b7_gpio14
    to: 'on'
  condition: []
  action:
  - type: toggle
    device_id: df0ababed560d611c362eb67795d2d5e
    entity_id: switch.k_ikea
    domain: switch
  mode: single

THE QUESTION:

How to get around this problem with unique device_id’s in different installations of home assistant.

If I can get a list of device_id’s from the old and the new installation I can write som code to change it around (but there must be an easyer solution outthere)

note: I know i dont need the device_id if i use old fashioned yaml for my automations. But apprently this is not the case for using the UI (or maybe im doing something wrong)

br

Actually very simple, you can always rename your device after the auto generate kick in. This way you dont need to replace all the changes on you code.

hi richard,

thanks for your suggestion.

Im not sure i follow you. Im looking for the device_id not the name. The name is the same in both the old and the new installation (it is given by a third party integration)

I cannot find anywhere where I cange change the device_id.

If I could change the device_id for a device It would still be a tedious affire - since i have 70+ devices
br

Agree with tedious process, however in my experiences most of the time HA will generate the same name. Unless you are customize everything. Anyway there are no easy way.

When creating an automation using the Automation Editor, opt for Service Call instead of Device Action. A service call is more portable because it only references the entity’s entity_id and not device_id.

  action:
  - service: switch.toggle
    target:
      entity_id: switch.k_ikea

When creating an automation using a text editor, it’s more natural to use Service Call because it’s shorter and doesn’t require you to find the value of the entity’s device_id.

1 Like

Hi 123 Taras,
thanks for your suggestion.

I tried it out and it looks like it is the way to go - even though there will be a lot of ‘redoing of automations in UI’ down the road :smirk:. But if that is the case I will be better prepared for my next migration (which will come)

In this example I use a sensor to turn on a heating switch. Do u have a similar suggestion for this case? As u can see it works fine for the action part. I just need to figure it out for the trigger.

- id: '1649237251559'
  alias: 'Heat on'
  description: ''
  trigger:
  - type: temperature
    platform: device
    device_id: 9d1f50db0b7b72c3004b4a31e59a1d6c
    entity_id: sensor.temperature_158d000424df8a
    domain: sensor
    below: 20
  action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id:
      - switch.v_stue
      - switch.v_kokken
      - switch.v_entre

br

Use a Numeric State Trigger.

    - platform: numeric_state
      entity_id: sensor.temperature_158d000424df8a
      below: 20

so easy - when ur in the know :grinning:

it looks like it is working - thanks for taking your time to help.

br

1 Like

You’re welcome!

BTW, you should know that when you assign the Solution tag to a post (only one post in the entire topic can be marked with the tag), it’s typically the post that answers the original question and/or provides a means of solving the problem. The Solution tag’s purpose is to guide other users directly to the helpful post.

In this case, you marked your own post with the Solution tag but it doesn’t contain any information to help solve the problem.

For more information, refer to guideline 21 in the FAQ.

it was my intention to asign the solution tag to you, but apprently i cant even pres button without messing it up :wink:

br