Can you post your code?
Trying a quick test for me worked no issues
{% set mylow = 5 %}
{% set myhigh = 1200 %}
{{range(mylow ,myhigh +1)|random|timestamp_custom('%X',false)}}
Can you post your code?
Trying a quick test for me worked no issues
{% set mylow = 5 %}
{% set myhigh = 1200 %}
{{range(mylow ,myhigh +1)|random|timestamp_custom('%X',false)}}
Very useful component!
Thanks for creating and sharing.
Thanks for a great tool.
Question: Is it possible for a variableās attributes to be save and restored after a restart of Home Assistant?
What Iāve tried:
The variableās āstateā is always saved and restored. I could stuff everything into a variableās state, or I could create more variables, but it would nice to have a variableās attributes saved too.
Iāve just discovered this thread, and since many of you are using it to positive effect, I donāt think Iām understanding it properly. How are āvariablesā different from, say, input_text types?
Variables are usually used on a temporary basis to help with a formula/calculation/template. Once the action /automation etc has been ran, this variable disappears.
input_text on the other side will remain, it all depends on what you want to do.
Actually, this is exactly what Iām looking for. I want to be able to set the volume on a media_player temporarily in order to broadcast a TTS then set it back to what it was. I just posted a huge thing in another thread wondering if this was possible.
There was just talk of people wanting the system to restore them on startup and that confused me as to the difference between variables and input_*. I want my variables to be temporary and go away when the current script/automation is finished.
Do you have to declare and define these variables before you can use them? I was hoping for more of an ad-hoc type of variable. Donāt know if thatās even possible.
it would look something like that, though Iāve not tested it this way
{% set initial_volume =state_attr('media_player.google_home_mini','volume_level') %}
Then you can you it like that
- service: media_player.volume_set
data_template:
entity_id: media_player.google_home_mini
volume_level: '{{initial_volume}}'
How do you end up with that template getting executed, but not under a āservice:ā heading? I donāt think the YAML syntax lends itself to what I want to do. I just canāt see how itāll all fit together.
what is it that youāre trying to do?
Can you describe?
Record a media_playerās volumelevel setting
Set volume on media player to something loud.
Play an announcement on TTS on media_player.
Set volume on media player back to what it was before.
Seems like overkill to have an input_number for this, because I donāt care about the value in it at any other time. I can do all those actions, just need to tuck away the āprevious valueā temporarily.
Edit: I see examples like this, and I canāt see the difference between variable and input_whatever:
I think this is what i want to do. Iām trying to set two variables using this component. Then, Iām trying to cycle through a series of if statements to find the condition where the two variables are equal (I just put in the text ālightā in the test code below). The portion of the code is:
set_ename:
alias: Set fname based on if statement
sequence:
service_template: >
{% if (variable.fname) == ālightā %}
- service: variable.set_variable
data:
variable: ename
value: light.mbr_right
{% endif %}
This in the script.yaml where the name of the script is set_name. The two variables (fname and ename) are set up in the config.yaml, and are working.
I get an error that the service_template isnāt permitted in a script.
Can anyone help me understand how I can do this?
Specifically, āthisā is to pass a name to the script, the script cycles through a list of if/then/else statements (which i tested in the template developer tool), and then when thereās a match, the variable ename is set to some text. I canāt for the life of me figure out how to do this. Doesnāt seem like it should be that difficult now that I have a variable I can useā¦
Update:
I modified the code to eliminate the if / endif lines (as well as a couple of other errant colons), the service_template line, and then ran the script. The variable ename does change to the value light.mbr_right, so at least I know that part of this worksā¦ Thanks again for any guidance! The updated code is:
set_ename:
alias: Set entity name based on if statement
sequence:
- service: variable.set_variable
data:
variable: ename
value: light.mbr_kirby
After declaring a variable, can I globally use it like this?
- alias: 'Garage Lights off'
trigger:
- platform: state
entity_id: binary_sensor.garage_motion
to: 'off'
for:
minutes: variable.off_time
action:
hi,
is this broken in hass.io version 0.84.1 ?
it was working fine prior to me upgrading.
Configuration invalid
CHECK CONFIG
Component not found: variable
thanks
YES!
Same problem like other custom_components have.
check here also:
full error in log:
2018-12-13 11:36:59 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.variable. Make sure all dependencies are installed
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/loader.py", line 92, in get_component
module = importlib.import_module(path)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/config/custom_components/variable.py", line 20, in <module>
from homeassistant.helpers.restore_state import async_get_last_state
ImportError: cannot import name 'async_get_last_state'
2018-12-13 11:36:59 ERROR (MainThread) [homeassistant.loader] Unable to find component variable
2018-12-13 11:36:59 ERROR (MainThread) [homeassistant.config] Package package_motion setup failed. Component variable does not exist (See /config/packages/package_motion.yaml:6).
@VDRainer would you be able to check if the solution in your other component could also be used in the component Variable? Maybe @rogro82 could you have a look whatās wrong?
Yes it should work again, I just merged the fix for 0.84 ( thanks to Tobias )
it does work, I can confirm, downloaded from your repo and replaced the old version.
Thank you very much.
btw this is on 0.84.1