#Home Assistant Command Line Sensor Issue with Python Script

1 messages · Page 1 of 1 (latest)

half jetty
#

I'm trying to create a Home Assistant Command Line Sensor to run a Python script that fetches the current free Epic Games Store game. However, the sensor doesn't appear in my entity list, and logs show:

"Forced update failed. Entity sensor.epic_games_free_game not found."

Current Setup:
Script Location: /config/python_scripts/epic_free_games.py
The script works fine when run manually via SSH ddon.

Sensor Config (in configuration.yaml):

sensor:

  • platform: command_line
    name: "Epic Games Free Game"
    command: "python3 /config/python_scripts/epic_free_games.py"
    scan_interval: 86400
    value_template: "{{ value | trim }}"

Problem:
The sensor doesn’t appear
Logs indicate the entity isn't created.

Tried So Far:
Verified the script runs manually without errors. It does
Checked configuration.yaml syntax (no issues).
Confirmed file paths and permissions.
Restarted Home Assistant.

Question: How can I resolve this issue? is there some kind of permissions issue. Any tips would be appreciated! 😊

half jetty
#

Guess not :d

fleet coyote
#

How long is the response? States can only be 255 characters long. You'd see an error to that effect in the log if it overflows

half jetty
#

first response would have been: "The Lord of the Rings: Return to Moria" Now its "Vampire Survivors"

#

so short

shrewd coral
#

Vampire Survivors is free on Epic Games?

#

that is a stupid fun game

half jetty
#

yea, Vampires survivors is todays game

shrewd coral
#

anyways, what's the python script

half jetty
#

my notice came through, but still with 'unknown". when i manually run the script i get the vampire survivors though

shrewd coral
#

Look in your log for errors, at startup it should run the script

#

then 24 hours from that it'll go again

#

'unknown' means it hasn't gathered anything yet

fleet coyote
#

didn't "command_line" change to a top-level tag?

shrewd coral
#

I can't remember

#

it did

fleet coyote
#

please format properly

half jetty
#

yea, working on it

sand mantleBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

fleet coyote
#

but the point is that you're using the wrong format

#

see the docs

shrewd coral
#

i.e.

command_line:
- sensor:
    command: ...
#

not

sensor:
- platform: command_line
  command: ...
fleet coyote
#

no need to post the python script

#

just read the docs above

half jetty
#

will do, ill go throuhgh it when i get home

fleet coyote
#

there's an exact example

half jetty
#
import feedparser

def get_free_eg_game():
    # RSS feed URL for the Epic Games Store free games
    feed_url = "https://feed.phenx.de/lootscraper_epic_game.xml"
    
    # Parse the RSS feed
    feed = feedparser.parse(feed_url)
    
    # Check if the feed has entries
    if feed.entries:
        # Get the title of the first item in the feed (the latest free game)
        latest_game = feed.entries[0].title
        
        # Clean up the title by removing the "Epic Games (Game) - " part
        # Assuming the format is consistent, you can split at the first dash (-) and take the second part
        cleaned_game = latest_game.split(" - ", 1)[-1]
        
        return cleaned_game
    else:
        return "No free game found"

# Test the function
if __name__ == "__main__":
    free_game = get_free_eg_game()
    print(free_game)  # Only print the cleaned game name

There we go. Was just trying to post it as Petro seemed curious

shrewd coral
#

You don't need that script btw

half jetty
#

im listenting

shrewd coral
#

you can use the rest integration and parse the name out

#

the rest integration can get XML or JSON from a website and use the data

#

Your template would likely be

{{ value_json.feed.entry.title }}
#
rest:
- resource: "https://feed.phenx.de/lootscraper_epic_game.xml"
  sensor:
  - name: Epic Games Free Game
    value_template: "{{ value_json.feed.entry.title }}"
half jetty
#

ooh, that would be a LOT more elegant. I'll dig into that later.

#

had no idea that was a thing

shrewd coral
#

Yep

half jetty
#

my next step, if i didnt get this working, was to redo it in node red, and use an addon in there to run python inside node red, instead of via command line. but this seems more fun to dig into

shrewd coral
#

The template may also be this
{{ value_json.feed.entries[0].title }}

#

either way, it's doable from rest

half jetty
#

sweet

#

thanks for the help! my YAML isnt great,

half jetty
half jetty
#

Just figured I'd mention, with the changes to the YAML it's working

Haven't changed it to the rest version yet

#

I'd love to change the icon, but that seems to be an entirely different challange

half jetty
#

and, just to finish following up, the rest command works (shock)