Elements in automations.yaml no longer work with latest release

I was using a version of HA which was at least two years old, I upgrade to the latest version and several automations have ceased to function 2021.9.7

  - alias: landing light on if out
    trigger:
      #first trigger     
     - platform: time_pattern
       minutes: '/5'
      # second trigger
     - platform: numeric_state
       entity_id: sun.sun
       value_template: "{{ state_attr('sun.sun', 'elevation') }}"
       below: -5.0
    condition:
      condition: and
      conditions:    
        - condition: template
          value_template: "{{ is_state('device_tracker.android_ab0cc2d3ebea9fac_lan', 'not_home') and is_state('device_tracker.moto_e6_play', 'not_home') }}"
        - condition: time
          after: '19:00:00'
#          after: 'sunset'
          before: '22:44:00'
    action:
      service: switch.turn_on
      entity_id: switch.landing_light

Any ideas what has changed ???
there is a second section which I post seperatly
TIA

Here is the second function which no longer works

#####################################################################
###  turn off LR lamp if wall lights are tuned on#####################
########################################################################

  - alias: Turn off LR lampif WL on
    trigger:
      platform: state
      entity_id: device_tracker.esp_552f65_lan, device_tracker.esp_55fd74_lan
      to: 'home'
    action:
      service: switch.turn_off
      entity_id: switch.living_room_lamp
...

Both of the smart bulbs are shown as home in lovelace when powered up,
this had been working without problem
Again any ideas

What do your logs say is the error?

Those automations you posted look OK to me at first glance.

there are a few errors and warnings 

2021-09-30 19:53:52 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /home/odroid/.homeassistant/automations.yaml contains duplicate key “action”. Check lines 35 and 59
2021-09-30 19:53:54 WARNING (MainThread) [homeassistant.components.http] The ‘base_url’ option near /home/odroid/.homeassistant/configuration.yaml:33 is deprecated, please remove it from your configuration
2021-09-30 19:53:57 ERROR (MainThread) [homeassistant.components.weather] The metoffice platform for the weather integration does not support platform setup. Please remove it from your config.
2021-09-30 19:53:59 WARNING (MainThread) [homeassistant.components.template.sensor] The ‘entity_id’ option near /home/odroid/.homeassistant/configuration.yaml:144 is deprecated, please remove it from your configuration
2021-09-30 19:53:59 ERROR (MainThread) [homeassistant.components.sensor] The metoffice platform for the sensor integration does not support platform setup. Please remove it from your config.
2021-09-30 19:53:59 WARNING (MainThread) [homeassistant.components.nmap_tracker.device_tracker] Your Nmap Tracker configuration has been imported into the UI, please remove it from configuration.yaml.
2021-09-30 19:53:59 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform legacy nmap_tracker

OK.

So did you take care of all of the breaking changes from your two year old version of HA and the one you upgraded to? looks like there are at least a few still outstanding.

And the issue with your automations might be the one listed as the first entry in that log you posted.

Did you look at line 35 & 59?

Hi, I got rid of the errors, still a couple of warnings, and I’ve tried to get the lighting section to function from lovelace ,But although I have the timing better , the time taken from switching on the wall lights to being shown as home on the gui, the l\mp does not turn off, It turns on \t the given time before dusk and off at 2330 .I also cant get the sun elevation to function as there are complaints its depreciated.



Logger: aiohttp.server
Source: /srv/homeassistant/lib/python3.8/site-packages/aiohttp/web_protocol.py:393
First occurred: 05:28:11 (1 occurrences)
Last logged: 05:28:11
Error handling request

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 314, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
  File "aiohttp/_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"


haven’t a clue how to get rid of that one

#dummy sensor for sun elevation


#  - platform: template#
#    sensors:
#      sun_elevation:
#        friendly_name: Sun Elevation
#        unit_of_measurement: "deg"
#        entity_id: sensor.time
#        entity_id: sensor.sun_elevation
#        value_template: "{{state_attr('sun.sun', 'elevation') | round(1) }}"
#        scan_interval: '00:05'
#  - platform: template
#    sensors:
#    sun_elevation:
#    friendly_name: "Sun Elevation"
#    unit_of_measurement: "deg"
#    entity_id: sensor.sun_elevation
#    icon_template: sun
#    value_template: '{{ states.sun.sun.attributes.elevation}}'

At the moment hashed out on configuration.yaml, as I keep getting Log messages the entity_id is depreciated, but which one ?,
The sun elevation is used to switch power from the solar PV panels to the hot water heater , I may be able to remove the need for that entity as I also can measure generated powere

Back to the automation to turn off a lamp if the wall lights are turned on , in lovelace

platform: state
entity_id: device_tracker.esp_552f65_lan, device_tracker.esp_55fd74_lan
to: HOME
from: AWAY

service: switch.turn_off
entity_id: switch.living_room_lamp

In developer tools

device_tracker.esp_552f65
ESP_552F65
	not_home 	source_type: router
ip: 192.168.1.94
mac: b4:e6:2d:55:2f:65
host_name: ESP_552F65
last_time_reachable: 2021-09-30T23:45:10+01:00
reason: no-response
friendly_name: ESP_552F65
icon: mdi:lan-disconnect

When off its shown as “not_home” or “home”
On lovelace its displayed as away or home, and which is correct in the yaml script upper or lower case.
It was so much simpler before integrating in to lovelace
TIA

entity_id in all template configurations is deprecated. So both of those template sensors shouldn’t have the field. The templates are smart enough to know how to update without them. So just remove the lines.

Thanks I’ve taken those out , but getting mapping errors

  - platform: template
     sensors:
     sun_elevation:
             friendly_name: Sun Elevation
        unit_of_measurement: "deg"

the log error points to the colon after “sensors”

The system cannot restart because the configuration is not valid: Error loading /home/odroid/.homeassistant/configuration.yaml: mapping values are not allowed here in "/home/odroid/.homeassistant/configuration.yaml", line 143, column 13

?? weird

If it looks like what you posted then it’s because of numerous indentation errors.

This is indented correctly (but lacks a value_template option):

  - platform: template
    sensors:
      sun_elevation:
        friendly_name: Sun Elevation
        unit_of_measurement: "deg"

It would help if the Check configuration had not been knobbled, It says it OK no matter what now
What value_template option ??
It also doesnt help that now the automations.yaml is overwritten by the system so you lose all the comments and notes made on the original

now getting

2021-10-01 19:33:06 ERROR (SyncWorker_0) [homeassistant.util.yaml.loader] while parsing a block mapping
in "/home/odroid/.homeassistant/automations.yaml", line 293, column 3
expected <block end>, but found '<block mapping start>'
in "/home/odroid/.homeassistant/automations.yaml", line 294, column 5
2021-10-01 19:33:06 ERROR (MainThread) [homeassistant.bootstrap] Failed to parse configuration.yaml: while parsing a block mapping

in "/home/odroid/.homeassistant/automations.yaml", line 293, column 3
expected <block end>, but found '<block mapping start>'
in "/home/odroid/.homeassistant/automations.yaml", line 294, column 5. Activating safe mode

Configurations.yaml
line 143 col 13 is the colon after sensor

  - platform: template
    sensors:
      sun_elevation:
        friendly_name: Sun Elevation
        unit_of_measurement: "deg"
#        entity_id: sensor.time
#        entity_id: sensor.sun_elevation
        value_template: "{{state_attr('sun.sun', 'elevation') | round(1) }}"
        scan_interval: '00:05'

“/home/odroid/.homeassistant/automations.yaml”, line 293, column 3

- alias: shack power if Richard is home
  trigger:
    platform: time_pattern
    minutes: /5
  condition:
    condition: and
    conditions:
    - condition: template
      value_template: '{{ is_state(''device_tracker.moto_e6_play'',''home'')}}'
    - condition: time
      after: 08:00:00
      before: '15:04:00'
    - condition: state
      entity_id: switch.shack_power
      state: 'off'
    - condition: state
      entity_id: input_boolean.notify_home
      state: 'off'
  action:
    service: switch.turn_on
    entity_id: switch.shack_power
  id: 875fe3fbaed7403fb5c41405a38cee59
- id: '1633035549082'    ###<<<<<<<,row 293 written by the system NOT me
    domain: switch
  mode: single

Now have a broken system that worked well until upgrade :frowning:

the behavior of the system overwriting the automations.yaml file is nothing new. I would be surprised if that wasn’t the case even on your “two year old” HA.

you can solve that by putting your manually written automations somewhere other than automations.yaml and then referencing that file location in configuration.yaml using an !include.

I’m still not sure why the system put in an id: since you already had one tho

The previous version I had did not alter the conf and automation files
So far no success trying to get the lamp in the lounge to turn off when the smart wall lights come on, the lamp comes on so many minutes before dusk and turn off at a set time.
And getting sun elevation control is in the same category, this is not so important as the lamp as sun elevation is used in the hot water controls and this time of year the PV panels are not generating enough to divert power to the hot water heater, so that has about3 months to fix. I think the previous version was .130, so old, but it worked

That version does alter the automation files. Every version does that has the UI automation editor. The automation editor was added in version 0.45, around May, 2017.

Hi , but the older version did not destroy the original versions, so If there were automations that
were not used , but useful for future use, they remained, now they are destroyed .

It’s done that since day 1 of the automation editor.

If you separate manually created automations from the ones created with the Automation Editor, the manually created automations are not reformatted and any comments you add are preserved.

If you keep all automations in the same place, whether they are created manually or via the Automation Editor, the ones created manually will be reformatted and any comments you add are removed.

The only way to prevent the Automation Editor from altering your manually created automations is to store them separately from the default automations.yaml file. This has been true for many years.