I am trying to do something that should be very simple.
That is assigning a new value to an input_number object,
Its a basic electricity twin tariff meter to go with the energy dashboard. I have set up three helpers.
and set the tariff in the energy dashboard as
input_number.tariff_now ($/kWh)
Then a couple of timers to set peak on and peak off times.
Then we have a simple automation that changes tariff_now to a fixed number, and this works:
alias: Peak tariff OFF
description: ""
triggers:
- trigger: time
at: input_datetime.tariff_peak_off
conditions: []
actions:
- action: input_number.set_value
metadata: {}
data:
value: 0.2532 ***<<<<<<this a fixed number***
target:
entity_id: input_number.tariff_now
mode: single
In essence, what I want to do is assign by altering the marked line above to something like:
value: input_number.tariff_offpeak <<<this is a variable
This doesnât work, nor do the huge number of other similar modifications. I have looked ad nauseam (over days actually) for a usable example. The explanations never say why they do what they do, none seem to work either.
So, can anyone tell me how to do this amazingly simple thing which is actually nothing more than
Very many thanks, most hugely appreciated.
I tried several versions of this, but none had quite the right combination of parentheses.
Yes, I did read âTemplatingâ which is probably excellent if you know all about how it works, and is no help if you do not.
OK so now it would be really great to understand what the syntax is doing, so I (really) would be eternally grateful if you could explain.
I am guessing
/value/ is a string so
"" tells the system inside is to be read as a string.
{{ .. I think implies inside is a bit of python/programming stuff
/states(/ no real idea what the states of the object is other than a number
'.. I would think was another string conversion.
Can you explain why this exact syntax is needed?
Note this is not actually for this specific item, but to try and get inside the head of the system/language/logic so itâs easier to interpret other examples. It would make quite a difference.
OK, I have looked at the state object.
The syntax is not entirely clear to me.
I am assuming that input_number.tariff_peak is the state âinput_numberâ of the object âtariff_peakâ.
As well as the state state.
It would then have other states such as âunitsâ as well as a timestamp.
Logically, then there should be a units.tariff_peak for example.
It would appear that there is a âstateâ of the object which here would be a number.
But you used âstatesâ, ah well.
Interestingly, the documentation doesnât mention the names to call up the states of a state object that I can see.
Most programming languages have the state name following the object name.
Iâm sure its perfectly obvious once you explain some of it.
As shown in the HA Docs - Building Templates - States linked previously, states() is a function in HAâs Jinja Template implementation that expects an entity ID string as the first argument and returns the value of the state property from the state object of that entity.
The state object of any entity will contain a minimum of 4 properties: state, last_updated, last_changed, and last_reported. Most entities will also contain a property attributes that contains a mapping of secondary information.
You can find the values for the state and attributes for each of your entities in the States tool.