Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONSchema for the frigate.yaml? #2421

Closed
felipecrs opened this issue Dec 9, 2021 · 32 comments
Closed

JSONSchema for the frigate.yaml? #2421

felipecrs opened this issue Dec 9, 2021 · 32 comments
Labels
enhancement New feature or request pinned

Comments

@felipecrs
Copy link
Contributor

Describe what you are trying to accomplish and why in non technical terms
I use the VS Code add-on on Hassio to edit the frigate.yaml. But oftenly I have to go back and forth to the documentation and try to restart the Frigate server to find out if I messed up with it or not.

Describe the solution you'd like
With a JSON Schema, we could leverage VS Code's YAML validation almost for free, by just configuring it to use it, or by adding this in the top of the YAML file:

# yaml-language-server: $schema=<urlToTheSchema>

Describe alternatives you've considered
Going back and forward to the Frigate docs and restarting it as mentioned.

Additional context
Not exactly the point here, but there are also tools which can create documentation in markdown format which can be used with Docusaurus based on the JSON Schema, so that you don't have to maintain the documentation in two different places. Only in the JSON Schema.

@felipecrs felipecrs added the enhancement New feature or request label Dec 9, 2021
@blakeblackshear
Copy link
Owner

This is why we migrated the config parser to Pydantic, but I don't think the endpoint that exposes the JSON schema was created yet.

@NickM-27
Copy link
Sponsor Collaborator

Looks like this was added https://github.com/blakeblackshear/frigate/blob/master/frigate/http.py#L337 so this issue can probably be closed now?

@felipecrs
Copy link
Contributor Author

I wonder if it's gonna work with the vs code add-on. An example on how to configure it would be nice.

@NickM-27
Copy link
Sponsor Collaborator

It seems you could do just add # yaml-language-server: $schema=http://frigate_host:5000/api/config/schema

@NickM-27
Copy link
Sponsor Collaborator

If that works then the docs can be updated to reflect that

@felipecrs
Copy link
Contributor Author

It worked! :D

I used: # yaml-language-server: $schema=http://ccab4aaf-frigate:5000/api/config/schema

@NickM-27
Copy link
Sponsor Collaborator

Closing this as it is now fully released

@printplaatreparatie
Copy link
Contributor

printplaatreparatie commented Apr 20, 2023

For some reason my VScode no longer connects:

Unable to load schema from 'http://homeassistant:5000/api/config/schema': No content.YAML(768).

I am however able to open the webinterface and can read the config JSON at http://homeassistant:5000/api/config. Is something changed or is there something wrong with my setup?

@NickM-27
Copy link
Sponsor Collaborator

@szymswiat
Copy link

@printplaatreparatie I have the same issue.

It does not work while I'm able to fetch the file using curl.

image

@h3llrais3r
Copy link

Getting the same issue: "Unabled to load schema..."
Any solution for this? I'm running the addon.
Have added it as mentioned in the documentation:
# yaml-language-server: $schema=http://ccab4aaf-frigate:5000/api/config/schema.json

@pbassut
Copy link

pbassut commented Jan 29, 2024

Doesn't work for me either.
added
# yaml-language-server: $schema=http://ccab4aaf-frigate:8123/api/config/schema
since I'm running frigate as an addon

@NickM-27
Copy link
Sponsor Collaborator

That is incorrect, you should check the latest docs

@printplaatreparatie
Copy link
Contributor

printplaatreparatie commented Jan 29, 2024

I'm still not able to connect although I can open the link in my browser without a problem.
# yaml-language-server: $schema=http://homeassistant:5000/api/config/schema.json
Screenshot_20240129_101709
Edit: Screenshot

@NickM-27
Copy link
Sponsor Collaborator

You should use an IP, vscode maybe not support loading from a hostname like that

@printplaatreparatie
Copy link
Contributor

I've tried it with the IP address as well, unfortunately without success. (Again, I was able to reach the page from within my browser.)

@pbassut
Copy link

pbassut commented Jan 31, 2024

I've tried it with the IP address as well, unfortunately without success. (Again, I was able to reach the page from within my browser.)

Can you post the full url you were able to reach?
Is the 5000 port a frigate port?
Cause home assistants port is 8123

@felipecrs
Copy link
Contributor Author

Where is VS Code running? Is it through the add-on?

@felipecrs
Copy link
Contributor Author

If it's through the vscode add-on, you should put:

# yaml-language-server: $schema=http://ccab4aaf-frigate:5000/api/config/schema.json

@printplaatreparatie
Copy link
Contributor

Config is shared by samba, and opened by Vscode on my laptop. This is the url when using the direct ip adress (which I would like to avoid, and which also not works):
http://192.168.178.152:5000/api/config/schema.json
The url that uses a hostname is also reachable in my browser:
http://homeassistant:5000/api/config/schema.json
Yes, 5000 the default port for the Frigate web interface that I opened in the Frigate config specifically to enable the use of the discussed JSON schema.

@felipecrs
Copy link
Contributor Author

It was supposed to work indeed. Are you using some kind of remote access in your vscode, like a devcontainer or ssh target? Make sure such environment can also reach the API. You can try curl it from there.

@printplaatreparatie
Copy link
Contributor

printplaatreparatie commented Jan 31, 2024

No, I have a script that mounts the config folder and opens VScode. For VScode it should be the same as opening a local file.

To be sure, I copied the file to the Desktop folder and opened it from there. The problem persists. I can also curl the link from my VScode terminal without any problem.

Edit: My OS is Kubuntu 22.04

Edit 2: I'm using the homeassistant validator for the other files with this configuration:

{
    "esphome.dashboardUri": "homeassistant:6052",
    "esphome.validator": "dashboard",
    "files.associations": {
        "*.yaml": "home-assistant"
    }
}

This will change the "language" of the frigate config file to Home Assistant. Switching to standard yaml doesn't make a difference though.

@felipecrs
Copy link
Contributor Author

I think it's important that the frigate file does not get interpreted as home-assistant, because the hass extension would enforce its own schemas otherwise.

How about you create a new vscode profile, empty, just with the YAML extension and try again?

@printplaatreparatie
Copy link
Contributor

The test that I did with the file in the Desktop folder was with an empty profile. Still no bueno.

@felipecrs
Copy link
Contributor Author

felipecrs commented Jan 31, 2024

Well, try any other schema, like this one:

# yaml-language-server: $schema=https://json.schemastore.org/helmfile.json

If it doesn't work, then the problem is somewhere else. Maybe in the YAML extension.

@printplaatreparatie
Copy link
Contributor

Actually, I was wrong about the profile. My default profile uses the home assistant language. Hold on, this might be the problem.

@printplaatreparatie
Copy link
Contributor

Okay, this is a bit embarrassing.. The YAML extension was not installed on my machine. The problem only became visible when I enabled the Home Assistant config helper last year. I think I removed the yaml extension, presuming the HA extension would do the job, which it will not.

Now the yaml extension is installed the error went away and I'm able to use the schema, even with the Home Assistant helper enabled.

Thanks for helping me out!

@pbassut
Copy link

pbassut commented Feb 5, 2024

I can't even curl from within an ssh session of HA itself

[core-ssh ~]$ curl -H "Authorization: Bearer dummy" http://homeassistant.local:8123/api/config/schema.json
404: Not Found

For my case: frigate is running as an addon.

I'm assuming I can't find the json because I'm hitting HA and not frigate.
If frigate is running as an HA addon, what's the port I should be hitting?

@pbassut
Copy link

pbassut commented Feb 5, 2024

Alright, was able to hit it from within HA by using http://ccab4aaf-frigate:5000/api/config/schema.json like it says in the docs.
But since I use VSCode outside of HA, I had to go to frigate's config(Frigate Addon > Configuration) and make it publish that port.

@printplaatreparatie
Copy link
Contributor

printplaatreparatie commented Feb 6, 2024

I get the confusion and made PR #9709 to make the documentation more concise.

Edit: New PR to master branch

@djdubd
Copy link

djdubd commented Feb 24, 2024

Okay, this is a bit embarrassing.. The YAML extension was not installed on my machine.

I am also trying to use the schema for validation, and my use case is with the embedded editor on the Frigate web interface. I have added the line to the top of the file using IP and hostname (resolves within frigate container, not using add-on). I cannot get it to work, so I wondered if this is because of the embedded editor not having the YAML extension, and it seems like it is. I am able to get validation working and the schema recognized when using desktop VS Code.

Is it possible to get the YAML extenstion bundled with Frigate? I realize that maybe the license won't allow this, but not sure.

If not it surely isn't a very big deal, and I can use a remote connection in VS Code to edit instead.

Thanks for all the info provided in this thread, I had wondered why it "wasn't working" for a while, but hadn't looked into it and with tips provided was able to figure it out!

@felipecrs
Copy link
Contributor Author

Frigate config editor comes with the schema configured already. It works for me without having to do anything.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pinned
Projects
None yet
Development

No branches or pull requests

8 participants