Hi!
I’m using appdaemon to set the value of a sensor.
sensor Pegel Leine:
- platform: template
sensors:
pegel_leine:
friendly_name: Pegel Leine
unit_of_measurement: 'cm'
value_template:
icon_template: '{% if is_state("pegel_leine_trend", "on") %}mdi:arrow-up-bold{% else %}mdi:arrow-down-bold{% endif %}'
When I set value_template:
to nothing, the value gets set nicely, but I get a warning in the log.
When I set value_template: ''
(empty string), appdaemon can’t set the value, but no warning in the log.
Is there a better way to do this? Or should the warning be checked?
Here is my appdaemon script:
import appdaemon.appapi as appapi
import requests
from bs4 import BeautifulSoup
import datetime
import time as tm
class Pegel_Leine_Class(appapi.AppDaemon):
def initialize(self):
time = datetime.time(0,0,0)
self.pegel_leine(time)
self.run_minutely(self.pegel_leine, time)
def pegel_leine(self, time):
self.log('')
self.log('-----------')
self.log('Leine-Pegel')
self.log('-----------')
self.log('')
start_time = tm.time()
self.log('Read HTML file')
file = requests.get("https://www.pegelonline.nlwkn.niedersachsen.de/Messwerte")
html_text = file.text
self.log('Soupify')
soup = BeautifulSoup(html_text, 'html.parser')
self.log('Extract value')
start = soup.find('a', href="/Pegel/Binnenpegel/ID/280")
pegel_leine_int = int(start.findNext('td', align="right").text)
self.log('Set state')
self.set_state('sensor.pegel_leine', state=pegel_leine_int)
self.log('Pegel der Leine: ' + str(pegel_leine_int) + ' cm')
self.log('Execution time: '+str(tm.time()-start_time)+' s')