Most basic question ever

Hello

I’m almost embarrassed to ask this question but I can’t seem to get my head around the xxx amount of platforms / sensors. I’m sorry but the cookbook examples are just too much for a beginner of home-assistant … .

I want to run a python script commanded by home-assistant and am just looking for a box in my interface how to display the output of this script.
I suppose I need to do something with hass.states but don’t get the concept how such an output (string unless some conversion is needed) gets displayed on the interface.

Referring to simple basic examples works as well …

thanks …

Maybe this?

I think if you want to get the output of a python script on the front end, you should add some lines to the script to update the state of a HA sensor. I prefer just to publish the output to a mqtt topic and then setup a mqtt sensor in HA and finally put that sensor on your front end.

If you just want to run a python script as from a shell, you need

But you could use one of the command line components if you want to actuall control something

cool, did not make that link :slight_smile:, I will try to figure out the mqtt sensors and post my solution.
thanks!

so, this mqtt trick indeed seems to work rather well:
if I add this to my configuration.yaml

mqtt:
  broker: 127.0.0.1
  username: stijn
  password: *********
  discovery: true

sensor:
  - platform: yr
  - platform: mqtt
    state_topic: sensor/thermostat/fubar #sensor/thermostat/fubar
    name: "time thermostat"

if I start a python script from the terminal it updates the sensor (using hassbian)

import subprocess
import schedule
import time

def thermostat_read():
    print(time.time())
    #cp = subprocess.run(["date"],shell=True,stdout=subprocess.PIPE)
    cp = subprocess.run(["ebusctl read Time"],shell=True,stdout=subprocess.PIPE)
    cp_string=cp.stdout.decode('utf-8')
    time_read=cp_string[0:8]
    msg1="mosquitto_pub -h localhost -t sensor/thermostat/fubar -u stijn -P **** -m "
    print(time_read)

    cp = subprocess.run([msg1+time_read],shell=True,stdout=subprocess.PIPE)

schedule.every(5).minutes.do(thermostat_read)
while True:
    schedule.run_pending()
    time.sleep(10)

So far so good. Now, of course I want to start/stop this script from the user interface. However if I add this shell_command, no buttons / switches etc. show up in the interface.
It doesn’t seem like adding and removing sensors happens very reliably in the interface but normally after restarts or reboots I get an updated sensor list at least, but not this time … .

shell_command:
  thermostat: python3 /home/homeassistant/.homeassistant/python_scripts/readtime_thermostat.py

any advice?
thanks!