GithubHelp home page GithubHelp logo

Comments (4)

joshuar avatar joshuar commented on August 25, 2024

Hey @Erreur32 that's super odd. I just tested on my machine by creating a script that simply echos that JSON output, and the agent accepts it and generates a sensor.

The "could not unmarshal script output" means the agent couldn't parse the output as either JSON, TOML or YAML (i.e., it doesn't recognise the output). Maybe the script is outputting some strange/unexpected whitespace?

You can use dasel to validate the JSON output of the script. Once you have dasel installed, a command like:

/home/debian32/.config/com.github.joshuar.go-hass-agent/scripts/check_version_ha_agent_json.sh > /tmp/script.output.json && dasel validate /tmp/script.output.json && rm /tmp/script.output.json

Should print out pass /tmp/script.output.json or a fail (some error)... if it failed to validate.

If it is possible, can you share the script and I can see if I can reproduce with the actual script?

from go-hass-agent.

Erreur32 avatar Erreur32 commented on August 25, 2024

Good point for validiting the json.
Very strange i have copy paste on online checking , and no error , but yes with dasel i sow the issue ;)

dasel validate .config/com.github.joshuar.go-hass-agent/version_installed.json
fail .config/com.github.joshuar.go-hass-agent/version_installed.json could not unmarshal data: could not decode object: invalid character '\x1b' in string literal
Error: 1 files failed validation

And apparently, the go-hass-agent version output also returns this ANSI control sequence along with the actual version.
--> "7.3.1[0m"

So I filtered it and now it seems to work :)
sed 's/\x1B\[[0-9;]*[a-zA-Z]//g'

my working script (for example propose):

#!/bin/bash

generate_json_output() {
    script_name="go hass agent version_installed"
    script_version=$(sudo -u debian32 /home/debian32/.local/bin/go-hass-agent version | grep -oP '(?<=go-hass-agent: ).*' | sed 's/\x1B\[[0-9;]*[a-zA-Z]//g')
    last_update=$(date "+%Y-%m-%d %H:%M:%S%z")

    # Creation JSON file (in case of)
    cat <<EOF > /home/debian32/.config/com.github.joshuar.go-hass-agent/version_installed.json
{
  "schedule": "@every 1h",
  "sensors": [
    {
      "sensor_name": "$script_name",
      "sensor_icon": "mdi:package",
      "sensor_state": "$script_version",
      "sensor_attributes": {
        "last_updated": "$last_update"
      }
    }
  ]
}
EOF
}

generate_json_output

cat /home/debian32/.config/com.github.joshuar.go-hass-agent/version_installed.json

Working well now, see my sensor :)

Question:
I have changed sensor's name, and now i see 2 sensors in HA, the last one is ok , but how can i remove the old one ?
There is a cache somewhere ?

from go-hass-agent.

joshuar avatar joshuar commented on August 25, 2024

I'm glad it's now working! Yes, the output of the version command has some escape sequences to colour the output:

image

As an alternative to your script, I could add a sensor that shows the agent version that only updates whenever the agent is started?

Hmm, I think you can only remove a sensor if it is no longer provided by whatever was sending it. Otherwise you could just hide it. You can follow the instructions for customising entities:

Select the entity, either from the frontend or by selecting the info button next to the entity in the Developer Tools “States” tab.
Select the cog icon in the right corner of the entity’s dialog.
Toggle the "Enabled", "Visible" switches, or click "DELETE" depending on your preference.

from go-hass-agent.

Erreur32 avatar Erreur32 commented on August 25, 2024

As an alternative to your script, I could add a sensor that shows the agent version that only updates whenever the agent is started?

As there is no automatic update, this seems like a good idea to me.

i have made a card and script to check online version on Github also:
Firefox_Screenshot_2024-04-23T07-35-46 722Z

from go-hass-agent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.