Frustrated with YAML

I just can’t seem to get any pasted in YAML code to work ever. Nothing I ever paste in from a published example works… Ever.

Is there a primer somewhere on this non white space agnostic crap? “Message malformed: extra keys not allowed” is the most useless (and only) message I ever get. Even the most simple example ends in the same horrible message:

Is there any kind of YAML programming interface with debugging available outside of HA that I could code and test in ? (I know there isn’t one within HA)
Is there a white-space agnostic automation language that works for Home Assistant? You can have sound logic, but end in failure because of a stupid space or tab. I hate it. I’ve written plenty of perl/php code in the past. With those languages, at least there was an http error log to look at.

Just my opinion, but I think YAML is a HUGE detriment to gaining user participation in Home Assistant.

1 Like

http://thomasloven.com/blog/2018/08/YAML-For-Nonprogrammers/

You have mashed together an automation and Template binary sensor configuration… and the binary_sensor block is nested as part of the service call, adding an “extra key” to the dictionary, which isn’t valid.

What are you trying to do?

All I was trying to do is get a “wiggle” out of the new method of fetching forecast data from weather entities. as published here: 2023.9: New climate entity dialogs, lots of tile features, and template sensors from the UI! - Home Assistant

You obviously understand the structures your looking at as being nonsensicle together where I do not. This is even more frustrating for me as I feel like an even bigger idiot now.

The blog post above is useful. Thank you for posting it, but how would I know where to begin creating a template vs an automation or script? These concepts are part of what’s missing for me. I know what a template does, but I don’t know where it’s supposed to be created or how to call or reference it.

  - service: tts.google_translate_say
     data:
     message: "Temperature is {{states('sensor.cahport_sensor_air_temperature')}}."
  cache: false

The code above works in the template section under developer tools, but I can’t seem to get it integrated into an automation because I don’t yet have all the concepts of HA.

The release notes show how to use the weather.get_forecast for both automations and template sensors, but each has it’s own requirements… they are not interchangeable or combine-able. The allowed configuration keys are listed in the docs for each under the heading “Configuration Variables”

Automations: Allowed Configuration Keys
Template Sensor: Allowed Configuration Keys

If you get the Message malformed: extra keys not allowed... error, check your configuration to make sure you don’t have keys in your configuration that aren’t in the related allowed list.

The first step is to identify the problem you are trying to solve or the goal you are trying to accomplish.

Template sensors are used when you need an entity to hold a dynamic value which is derived from other data; especially in cases where you need to have access to that value in multiple places such as automations, scripts, or in dashboard cards. As of 2023.9, basic template sensors can be created in Settings > Devices & Services > Helpers menu; more advanced template sensors like those with triggers must be set up using YAML in configuration.yaml, templates.yaml, or other properly included files.

In HA, a script is a sequence of actions. The sequence can include conditional and branching logic. You can think of scripts kind of like sub-routines that can be called by automations, dashboard cards, or other scripts.

Automations are essentially a script with at least one defined trigger.

The template editor tool only renders templates, it does not understand yaml at all. In the example service call posted, data is not indented properly. It should be at the same depth as service.

If you are just starting out, you may want to use the UI automation and script editors to build the “skeleton” of your automations, then switch over to YAML to add templates where necessary. There is a good (but slightly dated) video available on the ResinChem youtube channel that covers converting YAML automations to UI automations.

1 Like

Just to comment on your issue (not the solution to your problem) … I have found the following beneficial to me (but they are not free … I have the luxury of having access to such tools).

oXygen editor is what I almost exclusively use to write YAML. It already provides a good sensitivity of the indenting. Most of my YAML is a mounted Samba drive and I can access it from oXygen. Because it also provides a GUI that can expand and collapse chunks, it is ideal for restructuring YAML for dashboards and copying segments. That alone saves me hours of mistakes. It also has excellent search/replace functionality as well as tools to convert between JSON, XML and YAML.

The one drawback is that it is not integrated into Home Assistant to provide things like context picking of sensors. Here is a YAML view showing collapsed things to see how you can more easily edit in this. But as I said, it isn’t free. There could be other tools out there like this but I work extensively in XML and XSL and JSON so to me it is worth it.

Even JSON:

Or better, testing remote URLs that deliver JSON:

And I can create grouped projects and access the files directly from the interface:

Yes. Great suggestion… Done it. Know what I get?

"Message malformed: extra keys not allowed” It’s just not ready for folks who don’t know EXACTLY what they’re doing when they arrive inside the programming interface. I really do appreciate that You know what’s going on, but if you’re just walking up to this, It’s not set up for someone just wandering in… It’s not remotely intuitive.

As much as I protest, I’m not stupid. We all learn differently. There’s got to be a better way of communicating how HA backend works to those just coming into it.

If only I had an extra 5K a month to spend… I hate being poor.

$240/year for an individual = $20.month. It is not $5K. But still as I said, it isn’t free but my time is expensive, I can personally say it saves me 10x that much.

I am working toward a tighter integration as least for dashboards. If anyone knows whether Home Assistant has JSON schemas for automations and scripts then you could import those and context awareness of what is allowed and where … eliminating the “extra keys not allowed”.

Nobody said that you were… @kbrown01 and I have both just been trying to address issues you have mentioned.

When I started using HA, there wasn’t a UI automation editor. As someone with zero background in programming, computer science, etc… I understand your frustration. In fact, if you search deep in the bowels of this forum you may be able to find a post authored by me that is very similar to yours.

If the Automation editor and YAML aren’t for you, there are custom integrations like Pyscript or the APPDaemon addon that allow you to do automations and scripting using python… and there’s always Node-Red if you prefer a more visual method.

2 Likes

Well said. As I sit here I am rebuilding my Wallpanel GUIs for the LED lights.
This is the (current) product:

Started at over 1500 lines of YAML. Now applying decluttering through the “quick color” mushroom dots. Down to 920 lines.

Next is eliminating the custom:button card for the quick pick (1-9, +/-) which are modes for the LED lighting. Prediction, down to 200 lines of code. And because my chosen editor has macros and easy copy/paste/replace I can do every one of the LED sets with a few clicks. i.e. Replicate stack-in card from Patio and change patio_leds tp accents_leds.

Just did it for all those dots … took 5 minutes and not one mistake because it knows what to do and how to place it.

Then again I tend toward solutions and not frustrations, sometimes those solutions are not free.

1 Like

I have over 350 lines of YAML in my frigate config. It works. Frigate wasn’t easy to learn. It took a few days. It’s not just the YAML, but when you add it to cluelessness about the system architecture when your trying to get something done; it doesn’t help. I’m using HA core 10.5 and YAML editor leaves a LOT to be desired.

I have HACS installed, so I’ll also look into Pyscript as well. THX

@kbrown01 @Didgeridrew Thanks to both of you for taking the time, and reaching out. It’s nice to know I’m not just shouting at the ocean. I’m mostly irritated by my lack of progress. mostly…

Like all things worth doing this is going to take some perseverance on your part. Did you instantly know how to drive a car drive well?

Guess where you are on the learning curve:


Keep at it, keep asking polite and well structured questions, try not to get frustrated, it will get better.

1 Like