Hi!
I have just changed all action->actions, and service->action in my code. But I still have some deprecated things hanging around. For instance like this automation:
# Automation to turn on lamps when studio is active
- id: studio_lights_on
alias: "Studio Lights On"
trigger:
platform: state #WARNING: String does not match the pattern of "LEGACY_SYNTAX^".
entity_id: binary_sensor.mac_studio_active #WARNING String does not match the pattern of "^calendar\.(?!_)[\da-z_]+(?<!_)$".
condition:
condition: template
value_template: "{{ is_state_attr('binary_sensor.mac_studio_active', 'Sleeping', false) }}"
actions:
- action: light.turn_on
target:
entity_id:
- light.hue_play_right
- light.hue_play_left
- light.hue_strip_left
- light.hue_strip_right
Does anyone know why platform: state and my binary_sesor for my mac is giving this warning?
I have like 100 more if these…
I assume these warnings are in the VS Code editor? Are they actually coming from Home Assistant itself? What do the logs say?
If you are set on updating to the latest syntax - and please note that the legacy format will continue to work so you don’t actually need to do this - then check this image for the comparison.
In short; trigger: → triggers: (global find and replace - although NB this only currently applies to automations - for template triggers this key is still singular for the time being)
then platform: → trigger: (global find and replace)
then:
the top level condition: → conditions: (one by one replace, as individual conditions still need the condition: key in the singular)
WIth mine, I have a raft of trigger binary sensors which VSC is complaining about, but the syntax is such that it doesn’t like the changes either. I suspect that it’s something in the parsing within VSC, but it’s unclear how to fix these (or if I need to)…
eg
# Trigger Binary Sensor for enough Solar for Dishwasher
- trigger:
- platform: state
entity_id: sensor.excess_solar
binary_sensor:
- name: "Excess power for Dishwasher"
unique_id: excess_solar_for_dishwasher
state: "{{ ((states('sensor.excess_solar') | float(2) ) - states('sensor.dishwasher_peak_power') |float(2) ) > 0 }}"
VSC is complaining about -platform: state and the entity_id…
You don’t need to - the final authority on this is always going to be your logs in HA, and after that the Developer Tools > States. If the logs are telling you that a template sensor isn’t working or can’t be loaded, and it shows as ‘unknown’ or ‘unavailable’ in Dev Tools, then likely you have a problem. Otherwise, everything can be left as is in the legacy format. VSC is just an editor after all, and not the final word on the YAML syntax that HA actually accepts.
The only reasons to update to the new syntax seem to me to be if you can’t bear the sight of all that red (I think I’m actually in that group), and if getting familiar with it will help you help others going into the future (because in general we should be advising newcomers to adopt the new syntax I guess).
But to actually answer your specific question (!), assuming this is a template trigger sensor, then just change platform: to trigger:. The red squiggles under entity_id: should also disappear at that point.