Hi, I am migrating YAML to Python.
I menage to read and write the state of an entity this way:
# get the value of an entity e
def getE(e):
inputStateObject = hass.states.get(e)
inputState = inputStateObject.state
return inputState
# set the value of an entity e
def setE(e, val):
e1 = e.split('.')
service_data = {"entity_id": e, "value": val}
hass.services.call(e1[0], "set_value", service_data, False)
# demo:
x = getE("input_number.num_ess_sollwert")
setE("input_number.dummy", x)
BUT: in this case (tibber price info) there are all infos I need hidden in the attributes:
To read the prices per hour it works in YAML this way for e.g. three o’clock in the morning, addressing the price via an array:
target:
entity_id: input_number.tibber_preis_03h
data:
value: |
{{ (states.sensor.tibber_preis_info.attributes.today[3].total) }}
enabled: true
action: input_number.set_value
BUT: this leads to 2x24 stupid YAML blocks (24 price info each for today and tomorrow) instead of adressing the dictionary in Python someway like
# not working:
for t_hour in range(24)
price[t_hour] = states.sensor.tibber_preis_info.attributes.today[t_hour].total
Please help, thank you!