Display custom value on HA dashboard

I am trying to display a time value, only known in one of my Apps, on the HA dashboard. Seems like a simple thing, but can’t really find a way to do this.

Perhaps with set_state (but not supposed to use this), but then on what kind of entity?

Yes, set_state is the way to go. Just create a sensor with self.set_state("sensor.my_time_value", state = StringWithYourTimeValue). The sensor will not be persistent meaning that whenever you restart Home Assistant, the sensor will be gone and your app will have to create the sensor again.

Thanks, you put me on the right track, using the “cat method” now:

thats a really old thread with a method i used before i really discovered the possibilities from set_state.

a lot easier is it this way:

time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:$S")
self.set_state("sensor.any_name_you_like",state=time)

the first time the set_state gets called HA automaticly creates a sensor and then it gets updated when the set_state gets called again.

it is better because with the “cat method” HA keeps checking the file regularly (so more load) but you still get a lag before the sensor is updated.
with set_state, the sensor is updated immediatly.

Hmm right, tomas suggested that above, but I was getting an error. Tried again now, and seems the sensor is created in HA but Appdaemon still errors on it?

2018-06-04 13:03:00.381467 WARNING AppDaemon: Roxy: Entity sensor.roxy_ago not found in AppDaemon

Well, it’s a warning, but still…odd?

the warning do you get 1 time.
it tells you that the entity doesnt exist.
at the time that andrew created the set_state function he wasnt aware of the possibility to use it to create sensors. so the warning was a general one to let you notice that you use an unknown entity.

i theory there should be a function create_sensor that doesnt generate the warning, but just to get rid of a warning that would be a bit to much.

still, remember that you get the warning every time you have restarted HA. because with restarting HA the sensor dissapears untill you set the state the first time again.

i use this

      default_state = "anything"
      if not self.entity_exists("sensor.my_sensor"):
        self.set_state(“sensor.my_sensor”,state=default_state)

in the initialise from an app with priority 1
so that all my sensors get set as soon as i start AD.

you can also set atrributes like friendly name like this:
attributes = {“friendly_name”: “your friendly name”}

Thanks for the info! All working now, great.

1 Like