Why would you EVER want to lose YAML?

In the process of shifting my config to 0.110.xx I had a relatively trouble free run and set about my normal workflows to add functionality to my production environment which is now sitting on the 0.110.3 release.

Working away at an automation for a temporary fix related to how my outside lights are automated.
NOTE: the one I’m working on is:

Update Occupied Status From Laundry

Here is a snippet of my current working automation.yaml (NOTE how human readable it is):

#**********************************************************
# PI UPS Battery <90% Alert Notification Automation
# sensor.ups_battery
#
#**********************************************************
- id: PiUpsBattery<90Information
  alias: Pi UPS Battery <90 Information Notification
  trigger:
    platform: numeric_state
    entity_id: sensor.ups_battery
    below: 90
    for:
      minutes: 2
  action:
    service: notify.my_bot
    data:
      message: "INFORMATION! The UPS Battery is now below 90%"            

#**********************************************************
# Reset sonoff binary sensors on HA restart
# sonoff19 Power2
# Other? Just add more - data: items
#**********************************************************                              

- id: 'UpdateBinarySensorStatus'
  alias: Update Binary Sensor Status
  trigger:
  - event: start
    platform: homeassistant
  condition: []
  action:
  - data:
      payload: ''
      topic: cmnd/sonoff19/Power2
    service: mqtt.publish 

#**********************************************************
# Update Occupied Status From Laundry
# switch.laundry_door_downlight
# sonoff15/Event
# sonoff13/Event
# sonoff17/Event
#**********************************************************

- id: UpdateOccupiedStatusFromLaundry
  alias: Update Occupied Status From Laundry
  trigger:
  - entity_id: switch.laundry_door_downlight
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      topic: cmnd/sonoff15/Event
      payload: Movement_tankPath
    service: mqtt.publish
  - data:
      topic: cmnd/sonoff13/Event
      payload: Movement_Patio 
    service: mqtt.publish
  - data:
      topic: cmnd/sonoff17/Event
      payload: Movement_sidePath 
    service: mqtt.publish   

#**********************************************************
# Long Press testing
# sonoff03 Power1
# Works well!
#**********************************************************

- id: 'HoldForTankLight'
  alias: Hold For Tank Light
  initial_state: true
  trigger:
  - entity_id: sensor.outside_light
    platform: state
    to: 'HOLD'
  action:
  - data:
      entity_id: light.tank
    service: light.toggle 
  - data:
      entity_id: light.side_1
    service: light.toggle
  - data:
      entity_id: light.patio
    service: light.toggle
       

#**********************************************************
# Start Fan Speed Automation
#**********************************************************
# Update Rumpus Fan Speed OFF
# stat/sonoff05/POWER4
# input_select.rumpus_fan_speed
#**********************************************************
# This automation script runs when the rumpus fan speed selector is changed to off.
# It publishes its value to the same MQTT topic it is also subscribed to.
#********************************************************** 

- id: 'SetRumpusFanSpeedOff'
  alias: Set Rumpus Fan Speed Off
  trigger:
    platform: state
    entity_id: input_select.rumpus_fan_speed
    to: 'off'    
  action:
  - data:
      entity_id: light.fan_off
    service: light.turn_on

So after running up against a load of problems which I couldn’t quite solve myself I turned to the forum (as you do) and found a few ideas and made some changes but none of them helped so I thought to myself “Ok…lets see how the UI automation thingy works?” Well I opened it up and had a bit of a look at the UI and must admit it looks pretty nifty…however!!! The moment I saved a very minor change to one line of my automation an horrific and totally unexpected change (which was irreversible in the UI) was created.

Below is the same snippet after saving 1 line of 1 automation in my automation.yaml:

- id: PiUpsBattery<90Information
  alias: Pi UPS Battery <90 Information Notification
  trigger:
    platform: numeric_state
    entity_id: sensor.ups_battery
    below: 90
    for:
      minutes: 2
  action:
    service: notify.my_bot
    data:
      message: INFORMATION! The UPS Battery is now below 90%
- id: UpdateBinarySensorStatus
  alias: Update Binary Sensor Status
  trigger:
  - event: start
    platform: homeassistant
  condition: []
  action:
  - data:
      topic: cmnd/sonoff19/Power2
    service: mqtt.publish
# here    
- id: UpdateOccupiedStatusFromLaundry
  alias: Update Occupied Status From Laundry
  trigger:
  - entity_id: switch.laundry_door_downlight
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      topic: cmnd/sonoff15/Event
      payload: Movement_tankPath
    service: mqtt.publish
  - data:
      topic: cmnd/sonoff13/Event
      payload: Movement_Patio 
    service: mqtt.publish
  - data:
      topic: cmnd/sonoff17/Event
      payload: Movement_sidePath 
    service: mqtt.publish
- id: UpdateOccupiedStatusFromPatio
  alias: Update Occupied Status From Patio
  trigger:
  - entity_id: light.patio
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      topic: cmnd/sonoff15/Event
      payload: Movement_tankPath
    service: mqtt.publish
  - data:
      topic: cmnd/sonoff13/Event
      payload: Movement_Patio 
    service: mqtt.publish
  - data:
      topic: cmnd/sonoff17/Event
      payload: Movement_sidePath 
    service: mqtt.publish
- id: HoldForTankLight
  alias: Hold For Tank Light
  initial_state: true
  trigger:
  - entity_id: sensor.outside_light
    platform: state
    to: HOLD
  action:
  - data:
      entity_id: light.tank
    service: light.toggle
  - data:
      entity_id: light.side_1
    service: light.toggle
  - data:
      entity_id: light.patio
    service: light.toggle
- id: SetRumpusFanSpeedOff
  alias: Set Rumpus Fan Speed Off
  trigger:
    platform: state
    entity_id: input_select.rumpus_fan_speed
    to: 'off'
  action:
  - data:
      entity_id: light.fan_off
    service: light.turn_on

I won’t use the words I used here on finding my entire automations.yaml destroyed in such a fashion as the language nazis may ban me forever!

Does anyone here think it’s ok for a UI to do that to someones carefully considered YAML commenting by saying yes to a change in 1 line of YAML?

My final comment is contained in the heading and even has two words capitalized (god forbid!).

Why would you EVER want to lose YAML? Indeed!

1 Like

Exactly the reason why I don’t use the UI editor.

4 Likes

Exactly the reason I will never use it again as well.

So down the track and after a thousand more cuts will that (confusion) be only way you will be able to construct an automation?

We are humans and we need human readable tools!

See https://www.home-assistant.io/docs/automation/editor/#updating-your-configuration-to-use-the-editor for how to configure things to mix UI generated and hand authored automations.

1 Like

Thanks for the documentation link @AlohaDan however I will pass on spending any more time on that little bag a tricks thanks.

Steve,

I only use the GUI editor when I can’t figure something out or am trying something new… but I always keep a copy of the previous yaml as well - it’s how my backups work anyway.
I then play around in the GUI editor, save it, open the YAML and copy/paste the changes, restore that and reload automations.
Yes convoluted but a workaround. Maybe one day the GUI editor will cut the mustard.

2 Likes

This is explained in the docs @AlohaDan was refering to. If it was unexpected it simply means you didn’t read the docs :wink:

It is not a trick, it is the way to use both the UI editor and manual written YAML code. It allows you the keep comments, formatting etc. in your manually written automations. It works perfectly fine.

I understand the point you’re trying to make (as many others have done already) but your example doesn’t make sense as the automation editor does generate YAML. Maybe not formatted in the way you would like it to but it does output readable and editable YAML.

2 Likes

Yep you are spot in there (“Maybe not formatted in the way you would like it”) and I also did not RTFM as I was just having a look and mistakenly (stupidly I guess) thought it would only be editing the one automation not the whole file.

What is most surprising to me is that somebody actually sat down and designed the editor to strip out any human readable comments and even strip out whitespace as it was editing the YAML. It’s insulting to the human who put time into creating the automation and organise it to be read at a later time with notation on what it does and why it does it…whatever they damn felt like in fact!

You may call the result the editor produces as being human readable but I beg to differ. Its garbage to be fed to a machine that should only be seen by a machine.

The whole point of the ‘losing YAML opposition’ is that it strips out human readability and thus future easy editability and adaptability.

I fail to see how that could be considered progress?

Yes I keep copies as well @DavidFW1960 and restored the thing to its intended human readable state.

What really gets my goat is that there is documentation to tell a human to do this and that (to make it easy for a machine?) while the machine could just as easily copy your file rename it its own file and then edit away on it as it wanted.

Someone designed it to make it more work for the human it seems to me?

Its getting to be a struggle here (not using those words) when you come to such realisations and I wish I had never even opened that stupid editor to find out about it!

Steve,
I think there are many here who agree with you but to be honest you are missing the point that so many here are trying to make clear (not to you but to the devs cutting the path and the newbies who follow in it)
You are a newbie, you want an automation, you go to the gui, you get mangled code as you have shown that is not easy to read (which means you don’t read it and thus don’t ever bother learning the yaml and are thus 100% dependent upon the gui).
You hit a snag that the gui can’t deal with (say, I don’t want this automation to run if it ran in the last 7 hrs 23 mins (just a wild example)) Where do you go ? What do you do ?
You browse the forums and come across something close but you don’t know what you should do with it.
Someone tells you to cut and paste this into that and change this bit to read like so.
Ehhh… .??? No clue !
Okay someone leads you by the hand, you get the code inserted. You breathe a sigh of relief and say “I’m not going there again, yaml sucks (and I can’t even insert comments so I could maybe do it myself next time)” so you are locked into the gui and can only ever switch light on at this time etc.
It a closed, dead environment.

1 Like

In my own fumbling way I may have been trying to say something similar.

The path was cut to make it as hard as possible for humans to do anything advanced and discourage any further learning from the human.

It’s become very clear to me now I have stumbled on it for myself.
Reading those docs just reinforces the reality.

And the editor promptly strips the comments that ‘someone’ added to assist your understanding so you will never be able to go and reflect and build on your past achievement.

It’s a disgrace!

But this has always been the case ?
Many many post attest to that

1 Like

I think this behaviour actually makes sense if you know how the automation editor works. It loads the yaml file as a Python object. When parsing the automations.yaml file, the parser will just ignore the comments (hey, they’re called comments for a reason!) So, when the modified object is written back to the file, it will not contain any comments since Home Assistant can’t even read them. By the way, I’ve never seen a GUI tool that writes configuration files and also keeps its structure and comments intact.

To solve this, I’m not using automations.yaml for my automations, but another file. When making automations in the UI, they will still be written to automations.yaml and not overwrite my own automation file. This enables me to use the UI when needed, but still have commented and structured automation files.

2 Likes

Again there is a way to avoid this. And using the GUI you can add a description to your automations as well.

1 Like

Please don’t confuse me with someone who understands Python Objects.
It’s very clear this is all done to make it easier for the developer at the expense of the user.

If you are cool with that then so be it!

However, if you reflect on all the cool stuff that has been achieved here by a huge amount of clever people (who also shared their amazing achievements generously) they achieved that by using tools that were designed to make it easier for the new users to stand on the heads of giants.

Right now we are all heading towards having a black box toy that does some preinstalled/prepackaged cool stuff but cannot be easily modified unless you get the developers to figure it out OR pay for it perhaps?

I don’t think it’s right and it should be fought against by all!

Sorry…Not sure I’m clear what you are saying here?

Its been commented on numerous time, there are heaps of posts about how it works since the automation editor was introduced.

But you can still use YAML for automations, you don’t have to use the editor
i keep my automations in YAML and do like @DavidFW1960 does copy and paste to validate into editor if required

I am confused though, in numerous posts you have mentioned the issues of configs only being in the UI only, now your issue is with something that your against in theory the automation editor that you wouldnt want to use anyway.

I have had a slightly different but just as unsatisfactory experience with the UI writing a script (copied from DrZzzz) to implement actionable notifications. When I entered data into the service data it disappeared on clicking save. It did not work so I had no idea if I had wrongly capitalised or made a spelling mistake.

I reverted to yaml and it was so much easier.

I agree that moving from the initial user base who gave of their time to develop all the integrations will discourage further development and the project will stagnate. Yes there are a few “ultra” developers but is the ability to learn and do simple coding with yaml and python that attracted me to Home Assistant and to extol its virtues to others in the first place.

IMHO deprecating the use of yaml is a move in the wrong direction. It gives me pleasure to think I’m smarter than I am when I do a simple bit of coding that works. Click and Play has its place but not at the expense of those who joined this project because of it’s flexibility.

2 Likes