#templates-archived
1 messages Β· Page 91 of 1
I know the templates result into corresponding devices/radios
I'll change the yaml and check
btw this is a better method for templates:
"{{ states('input_select.playback_device') }}"
I've seen both around but never understood the difference. Are there pros/cons sort of thing?
basically prevents errors from being printed in the log
IMO it also looks cleaner especially when you start tapping into state attributes
Yayyy that worked now π Thanks a lot!
Haven't play much with templates before so it's all new for me
Ah another quick question. For the input_select dropdown options is it possible to set up friendly names?
Rather than choosing from e.g. media_player.kitchen_dot etc to Kitchen Dot
you could change the input select options to what you want and use templating to convert it to an entity ID
entity_id: "media_player.{{ states('input_select.playback_device').lower().replace(' ', '_') }}"
if the input select option is Kitchen Dot that would generate media_player.kitchen_dot for the service call
Hmmm it's giving me media_player.h_o_m_e e_c_h_o
Is there any good links you know for learning how to create templates like that?
I don't know what I should be googling exactly
oh whoops lol
correction above
the page i linked above is helpful and also has a link to the jinja2 templating engine docs which is what home assistant uses for templating
apart from that the online python courses i took were helpful in learning how to do other things with templating/string manipulation
I know what I'll be doing when I'm off work
it's pretty fun. you can also test templates at developer tools > template before adding them to automations, sensors, etc
That's what I've been doing π
brings a tear to my eye
Hi folks! Is it possible to use a template to extract data from an event?
Those are triggers. Not exclusive to automations?
Triggers are exclusive to automations, hence why that's in the automations part of the docs π
Hehe... Let me explain my intentions then. π
you want an eventsensor, not possible with core, there is a custom option
I use an ESP to pass some data to HA. I can listen for the event on HA, but I was wondering if I could set up a template sensor to hold the data I need.
@rugged laurel Ahh!
You could fake it with an event trigger and in input numer/text/whatever
okey... sure...
do that βοΈ
number, even π€·
I'm lazy, if I have the tools to assemble a Heath Robinson contraption, why not π
Thanks guys! I might be back when my attempts on this isn't working! π
I've been working to get sensors that track the number of lights, windows, etc, on/open, whatever. This generates the count:
{{ expand('group.all_lighting')|selectattr('state','eq', 'on')|list|count }}
But, the group's state doesn't update when another light comes on, only when the first one does, or the last ones goes off. So, I need a heartbeat it seems to get the expand() to execute periodically. Here's what I'm trying: (time updates by minute)
{% if (strptime(states('sensor.time'),'%-M')|int) in range(0, 59) %}
{{ expand('group.all_lighting') | selectattr('state','eq', 'on') | list | count }}
{% endif %}
Seems that every minute I'll execute my expand(). I'll see.
Is there a better way, or a better heartbeat to use to force template sensor updates?
Hey folks, I have a thermostat that is showing the temp as 10x the actual value. Can someone explain how I might make a template and divide the temp sensor value by 10?
@dusty hawk it won't update because the template can't resolve any entities to update from. You need to list out all the entities in the group to the entity_id field.
@slate ferry look up template sensors & templating. {{ states('sensor.xxx') | float / 10 }}
Thanks Petro, Iβll play with that and see what happens.
fun thing i just got bit by, states('sensor.xxx') | float returns 0.0 for unknown / unavailable
i have a template that averages a bunch of sensors and that 0 tanked the value π
Solution is to reject the values before the divide for the average
value_template: >-
{% set sensors = [
states('sensor.living_room_temperature')|float,
states('sensor.office_temperature')|float,
states('sensor.thermostat_temperature')|float
]
%}
{{(sensors|sum / sensors|reject("eq", 0.0)|list|length)|round(1)}}```
hi all, can a sensor template hold one url as the value, something like this: `
- platform: template sensors: ring_video_url: friendly_name: "Ring video url" value_template: "{{ state_attr('camera.front_door', 'video_url') }}"
because what i get is a state unknown
Check the template in
-> Templates and check your log file for errors or warnings
yep, thak you, so i found this on the log: . State max length is 255 characters.
Hi all. I'm trying to test a REST sensor. They query returns the expected JSON but how can I use a value_template to parse out just the 'ltebandwidth' value? Thank you!
{"data": [{"ltebandwidth": "10 MHz"}], "meta": {"limit": 20, "next": null, "offset": 0, "previous": null}}
"{{ value_json['data'][0]['ltebandwidth'] }}"
@buoyant pine thank you that worked perfectly. I should have asked before but because the value is '10 MHz' and not 10, will the sensor card line graph still update as the value changes? Or if not is there a way to strip off the ' MHz' ? Thanks again!
{{ value_json['data'][0]['ltebandwidth'].replace(' MHz','') }}
if you use that and set a unit of measurement for the REST sensor it should work with the line graph
unit of measurement being MHz
Trying to get a template binary sensor working to pull an attribute from an Ecobee thermostat. Have tried the following:
binary_sensor:
- platform: template
sensors:
furnace_fan_living_room:
friendly_name: Fan Running
device_class:
value template: "{{ is_state_attr('climate.entryway' ,'fan' ,'on') }}"
Any thoughts on where I'm going wrong?
@deep tapir To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks. Here's an example:
```
code here
```
Watch the animated gif here: https://bit.ly/2GbfRJE
DO NOT repeat posts. Please edit previously posted message, here is how -> https://bit.ly/2qOOf1G
I get:
Invalid config
The following integrations and platforms could not be set up:
binary_sensor.template
Please check your config.
Take a look before that
Thanks. The underscore for value_template must have fallen out in one of the variants I tried. That fixed it!
Hi can someone help with this please
sensor:
- platform: file
name: smartctl
file_path: "/smartctl/test.json"
value_template: "{{ value_json }}"
- platform: template
sensors:
dev_sda_smart_status_passed:
value_template: "{{ value_json.smart_status.passed }}"
dev_sda_temperature_current:
value_template: "{{ value_json.temperature.current }}"
basically I need to pull about 10 sensors out of a json file, but just want to access the file on the disk once
so the value_json needs to change to the sensor.smartctl
but i;m not sure about the valid syntax
Probably {{ states('sensor.smartctl').smart_status.passed }} but I'd get that first sensor in and then test in
-> Templates
ok cool
i'll have a look
thank you Tinkerer
I'm coming back with a harder question soon π
hmmm
Error: 2020-05-07 20:08:26 ERROR (MainThread) [homeassistant.components.file.sensor] '/smartctl/test.json' is not a whitelisted directory
do I just have to put the file in the config directory or something?
I tried docker exec -it homeassistant bash and I can read the test.json file
Or move it, yes
ok thank you
What would be the optimal location for something like that
I can just put it anywhere
"that" goes in the section shown there π
That section can go anywhere in your config
ok
hmmm
sensor:
- platform: file
name: smartctl
file_path: "/smartctl/test.json"
value_template: "{{ value_json }}"
test.json
{
"temperature": 25,
"unit": "Β°C"
}
I checked HA can read the test.json file
There is no error in the logs
But sensor.smartctl is blank
It's not unavailable it's just an empty sensor
I'll try get rid of value_template line
hmm im stuck
the problem is the file sensor only reads the last line of the file
hmm i think i need to use command_line sensor to read more than one line from a file
i got the sensor to take json on a single line
but im having trouble going to the next step of extracting values from the sensor
sensor.test = {'test': 'hello world', 'name': 'mike'}
but can't figure out how to get hello world out of that
because all the examples don't extract json from existing sensors
{{ states('sensor.test').test }}?
You may alternatively need https://www.home-assistant.io/docs/configuration/templating/#tofrom-json
can u upload a picture in discord?
(screenshot)
{{ states('sensor.test').test }} doesn't work
I've read https://www.home-assistant.io/docs/configuration/templating/#tofrom-json - but i don't fully understand how to put it into practice
another go : http://iforce.co.nz/i/tmxxak4q.b1s.png
yup i got that going but still can't get a value out
^ as per above photo
mmm lemme add your file sensor and test
its ok im think im almost there
it's wierd I think the value_template: "{{ value_json }} doesn't work properly, if i just read the file as text and then turn into json later it works ok
Sharing code ... as images π±
its show i can share the template output lol
actually its the quotes
{{ my_testb.test }}
{% set my_testc = states("sensor.test_b")|from_json %}
{{ my_testc.test }}
yeah :/ screenshots arent the easiest way for us lol
I have to change the quotes because the value_template: {{ value_json }} turns the " into ' then when I try to use 'quotes' in the templating it throws an error.
Can multiple entity_id be listed under... ?
turn_on:
- service: switch.turn_on
entity_id: switch.internal_mount_1tb
- service: switch.turn_on
entity_id:
- switch.switch_one
- switch.switch_two
π¦
" State max length is 255 characters "
start again.
@little gale Yup, same as any other place, separate with commas
- service: switch.turn_on entity_id: - switch.switch_one - switch.switch_two
this would work as well right?
yes both work
They're the same, just different to humans
To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks. Here's an example:
```
code here
```
Watch the animated gif here: https://bit.ly/2GbfRJE
DO NOT repeat posts. Please edit previously posted message, here is how -> https://bit.ly/2qOOf1G
Backtick is the one next to 1οΈβ£ on the keyboard usually
':-)
I'm still struggling with this bolean (MQTT) sensor:
- platform: mqtt
name: "rob_aanwezig"
state_topic: "domoticz/out/floorplan/rob"
value_template: "{{ value_json.nvalue }}"
payload_on: "1"
payload_off: "0"
After a restart of HA the sensor is off and I would like it default on. Help is appreciated.
On restart, does that topic hold the on or off value?
The on value.
Odd, I'd have expected it to work then π€·
The topic from Domoticz is only active when the switch is activated.
Can you have it set the retain flag?
I don't think so.
Then the best option would be to have an automation that publishes the right payload to the topic when HA starts
Ok, I will look into that. Thanks!
Can anyone sanity check this template, please?
I'm using the structure given on https://www.home-assistant.io/integrations/template/ but still getting errors due to indenting on the first line with friendly_name:
Please don't say I have an error or describe an error. Share the whole actual error message so we can help you.
bad indentation of a mapping entry at line 55, column 25:
friendly_name: 'NΓ€chstes Startdatum'
Missing `?
anyone using rhasspy here ?
Pasted it in there, saw the error. Stripped out the second platform block, saw the error more clearly π
Sounds like #voice-assistants-archived @wary fiber
@arctic sorrel nice - thanks for the hint!
No worries
well it s a script_intent :p @arctic sorrel
The thing you named is a voice assistant π
hehe oki π
Maybe you were planning on asking a template related question?
yup dont know how to get the siteId value from the intent in my template
Please use https://paste.ubuntu.com/ or https://www.hastebin.com/ to share code or logs.
Why don't you share all the information you have, and then maybe somebody will be able to help π
pasting π
i included the mqtt result
i just want ( for testing ) a persistent notification with the siteId name
but the value is always empty
π’
Patience π
Somebody who can help will be along, eventually, and if not you can always post on the forum
yup π
Hello, I'm reposting this here ... https://paste.ubuntu.com/p/Rcy5dSztzC/ http://iforce.co.nz/i/3zevef33.ciy.png even after research i'm really missing something even if you said "first rue of templating" ... https://paste.ubuntu.com/p/bMY6WQbpYf/ this does not work either .... nothing working. it looks ridiculous
oh and this is not working either before you ask https://paste.ubuntu.com/p/3NBNkBkBNd/
i feel like i'm doing just like the documentation examples. they are using temperature i'm using power.
what are you trying to do ?
i want google to tell me the consumption when i call this script
Where is data_template?
Become a real Jinja2 Ninja! Don't worry my Genin, we are here to help! You can find the docs at https://www.home-assistant.io/docs/automation/templating/ - and don't forget rule #1! Please use https://www.hastebin.com/ or https://paste.ubuntu.com/ to share code or logs
test1:
alias: test1
sequence:
- data_template:
message: "{{ state('sensor.machine_a_laver') }}"
entity_id: all
service: tts.google_translate_say
Important Template Rules
- You must use
data_templatein place ofdatawhen using templates in thedatasection of a service call.
was following https://www.home-assistant.io/docs/configuration/templating from the begining ... π€¦ββοΈ
@arctic sorrelbtw i posted about my problem on the forum 3 days ago ... still no anwser π¦
π€·
And you're tagging me to tell me that because ?
I have no magic wand to force people to help you
People give up their time for free to help
I know many people...
If you read and followed the sticky post on the forum, you've done all the right things there
Tagging folks to nag/demand help just leads to you being blocked or banned π
yeah guess so
https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371/ in case you missed the sticky there π
yup i ve read it ... tho there s so little infos about intents handling :/
Yeah, that post is about how to ask a good question
and searching :p
sorry english is not my native language sometime i have difficulties to be clear
Could you please suggest me how to debug this error `Error doing job: Exception in callback async_track_state_change.<locals>.state_change_listener(<Event state_...480144+02:00>>) at /usr/src/homeassistant/homeassistant/helpers/event.py:81
Traceback (most recent call last):
File "<template>", line 1, in top-level template code
TypeError: '>' not supported between instances of 'NoneType' and 'int' . ?
i m kinda new to homeassistant but i 'd say one object you are trying to use doesn t exist
or you are not comparing the same type of data
e.g. "20Β°C" and "20"
I've a lot of automations and scripts. I'm trying to understand if and how I can narrow the debugging. I wish I had catch this error sooner π¦
does this happen on startup by any chance?
Let's say I want something like this:
entities:
- data_template:
message: "{{ state('battery_level') }}"
entity_id: "all"
But this doesn't work, what am I doing wrong?
what is the context for this?
I'm trying to get a custom:battery-state-card with all battery_level states on it. So I want the list of entities to be populated automagicly π
that's a #frontend-archived question
Sorry, to be rude, but how is frontend going to answer this? Because I was just send to this channel...
You can't do that with a template
One whole card supports that, the auto-entities custom card
Ok, so, let's say I want to create a group with all battery_level entities. How would I go and do that?
Well, you can't use that to add them to a card
You simply follow the instructions for the #frontend-archived card you're using
If you want to create a group, you create one with all the entities listed - again, no templates
Ok, I'm kinda surprised about this. Not that it isn't possible with templates, but more that the "filters" like with "exclude / include" with some integrations isn't widely added to things like this. Would that be something to create a feature request for? Would save a lot of typing for a lot of people, and there is the benefit of it being self populated when adding entities to HA.
Yeah, I know. But do you, as a developer and more acquainted with the HA core, think it is a viable feature? Or would it give to much overhead to the system?
Tinkerer
Developer
pick one

Assumption is the mother of all ...
My Python skills are ... rusty. I think it's been a decade since I last touched Python, maybe more
There's no harm in opening a feature request
I touch mine several times a day
Ok ok, I'l do that. π
WHOA there.. only I do that without invitation
@thorny snow, I'm not following... Sorry I'm autistic (really).
Haha.. just making a joke as if you were talking to me, and I knew you weren't
I touch mine several times a day
@thorny snow Ah, now I get it.... Sorry... Slow to this. Obviously.
Have fun then! π
hahaha
automation:
- alias: "sda"
trigger:
platform: states
entity_id: smartctl_sda
action:
service: script.turn_on
data_template: >-
{% if is_state('sensor.smartctl_sda_json','0') %}
entity_id: script.sda
{% else %}
entity_id: script.do_nothing
{% endif %}
Does anyone see the problem with that it gives config invalid error
Invalid config for [automation]: Invalid platform specified @ data['trigger'][0]. Got None
expected a dictionary for dictionary value @ data['action'][0]['data_template']. Got None. (See ?, line ?)
else_if?
no, that's a guess
actually thats not a mistake
did it work?
{% if is_state('sensor.smartctl_sda_json','0') %}
entity_id: script.sda
{% else %}
entity_id: script.do_nothing
{% endif %}
works in template editor
yes
ahh
actually no
thats just an entity_id
i could try change that to something else
and see if it works
like if 1 == 2
ok, curious... why does it have json in the name? I've never seen that as a default entity_id
its one i created from reading a json text file
so yes, it's a template
sensor:
- platform: command_line
name: smartctl_sda_json
command: "/bin/cat /config/smartctl/sda.json"
value_template: "{{ value_json.smartctl.exit_status }}"
json_attributes:
- smartctl
- smart_status
- ata_smart_attributes
- power_on_time
- power_cycle_count
- temperature
scan_interval: 10
automation:
- alias: "sda"
trigger:
platform: states
entity_id: smartctl_sda
action:
service: script.turn_on
data_template: >-
{% if '1' == '2' %}
entity_id: script.sda
{% else %}
entity_id: script.do_nothing
{% endif %}
^ that is invalid config as well
must be a space_bar or something causing an error
yes
look at line # 5
entity_id: smartctl_sda
should be entity_id: sensor.smartctl_sda
true LOL
god damn
I am terrible at this
im spending forever trying to make the hdd sensor that tracks all my HDDs (i have 15)
does anione know how to make a template for a light brightness slider to be converted to a fan speed slider?
I receive the following messages from the device Dimmer2IS0
and need to send Dimmer1:{dim percentage 0-99} -->> dim dimmer one
give us the value from the light template and then what you need it to look like for a fan template
what are you actually trying to accomplaish with this?
well i add a light entitie direct in yaml
i assume it's a custom card that works for lights but not fans?
oh, you don't like the low med high off card?
or maybe controlling a fan with a light dimmer switch?
well, that's bad
well i need the dimming slider as mandatory. is to be used in a extractor to a grow room eheheh and need to be set by % in order so i can maintain oerfect temps
yes
I use a centrifugal in dimmer1 and a inline fan in dimmer 2
so a regular fan controller won't do becuase you need it to go lower than low?
It does. i have regular analogue dimmers and does the job
this hack armtronix dimmer copy does also.
well, tell HA it's a light
it doesn't know the differenct if it's just a dimmer
Just name it fan
In on off i can do it with no problem but i need to have the capabilitie to change dimming values from ha
and use a fan icon
so what part doesn't work?
so use brightness_pct to map your value.. easy peasy
your not asking a specific enough question π
look the switch/fan is working ok in the mather of on and off but i want to put a slider to control brightness/fan speed for it. The Mqtt message that I have to send is Dimmer1:{dim percentage 0-99} -->> dim dimmer one
I see.. ok
Now i do not know how to make a slider that send message
make an input slider
do you need the code i have now?
map input slider to your mqtt
1 sec
light:
- platform: mqtt
name: "DIMMER1"
command_topic: "testesub"
payload_on: "R13_ON"
payload_off: "R13_OFF"
optimistic: true
qos: 0
retain: true
i have the code already made.. gimme a sec to find it
the payload that ive receive is Dimmer1IS0 when off and Dimmer1IS+0 when on. but the command R13_ON that is dimmer on puts the dimming value at 100% every time.
I assume that i have to template the final part of that sentence in order to have also sensor if the light is on.
thanks im just giving ideias
Like if Dimmer1IS0 ZERO show light off, if more than 0 then show light on icon
because if i used the switch instead of light it just goes on off position after a few seconds. because the message i have put on the state only knows zero and 100.
@dusk moth posted a code wall, it is moved here --> https://paste.ubuntu.com/p/qzwBDfkfJH/
DAMMIT
sorry
it happens to me all the times
need to set the min speed to - also
"0"
did you get that?
im reading the code
just a sec
hide entity needs to go also
you can do a slider also, I just did a number
will paste in the config and restart the server to see the changes.
will give reply of it
π
make the fixes I said
min 0
and hide entitiy = delete
that part sorry i do not understand
the entitie i have now you mean?
delete this line: " hide_entity: false"
ahh ok got it
now have 3 new entities, but need to make slider based on the number right?
sorry im kind of dumb in programming
humm the slider goes on his own to 0 and does not control the dimmer
no, the mqtt controls the dimmer
I used the topic you gave
but you can make that an input_silder
the topic i gave is the right on. but the payload change
will send the complete payload for you to see
is the fan actually listening on that topic though?
https://paste.ubuntu.com/p/HKWHK499Pq/ look only for -m front.
and i receive a message in testepub with Dimmer1IS(0~99)
Ok, your on/off already works?
yes
i have the thing in my front next to the computer
ok, 1 sec
if i click the fan icon it does turn on and off but only 0% and 99%
did you add the input_number.fan_speed_pct to a card?
it should be a slider by default
it is but does not control the dimmer
cool there you go
not yet... 1 sec
the command topic is not the same as the reply from the dimmer
try this for the payload
payload: '"Dimmer1":{{ trigger.to_state.state | int }}'
removing the outer squiggles
squiggles?
LOL the "{"
ahh. non english native
I could tell, it's ok
payload: '"Dimmer1":{{ trigger.to_state.state | int '
this ?
payload: 'Dimmer1:{{ trigger.to_state.state | int }}'
I believe the word you are looking for is braces
squiggles dammit
heheh
so what do YOU see wrong with the template I gave?
I know you can fix it
well is rebooting.
ok, that only sets the fan, not the slider.. so we'll fix that when the tx part works
well
good and bad news
it didn't blow up is good news
if i track the slider it does turn on but goes off on is own
ehehehe
the slider goes back off? yeah.. that's expected still
we just want to make the fan speed work first
but now it seems controlling it
will try the button
turn on and off on the button does not affect the slidder
it turns on and off but no feedback on the slider
the slider isn't going to work yet
ok, see the 2 automations?
ahh ok. like ive said is too much sand for my truck
no, it's not.. it's just all new
but with your kind help im getting there
it'll be your turn to help someone else soon
so how do you know the fan speed?
i receive on the topic: testepub the following message: Dimmer1IS0 or Dimmer1IS20 etc
you can make an automation to set the input slider to 0 when you hit the off button
is that the same example you gave earlier?
yap
the same topic??
i have a publish topic and a subscribe one
there are not the same
so the RX msg automation needs to listen to the pub topic so it can listen for speed
what's that topic
i receive info in testepub
and send commands in testesub
- alias: Fan Speed RX msg
trigger:
platform: mqtt
topic: 'testepub'
just change the topic
well i see now that the names i choose are misleading no?
restarts and restarts are a pain in the ass
no change mate
I know, I need to fix the value
so it should look like "Dimmer1:{45}"?
from mqttfx
you realize you can listen to mqtt from inside HA?
and publish too I think
it's difficult to see those pics
yes. but was allready instaled in the mac. now i know
why is the data "214"
oh... sequence
I can't see what that says.. Dimmer1???
Dimmer1IS0
dimmer1 is 0
but writen as the first sentence i put
Dimmer1IS0 !!
is that the dimmer name?
it looks like that's Dimmer1 I S O
no no spaces
is that the brightness value somehow??
yes
ISO?
that last number goes from 0-100 it may be handled like brightness
IS(zero)
OK..... so... DIMMER1 Intensity "50"
OH... IS ZERO
is Dimmer1IS50
WOW... ok... this changes things because now you have to split the Dimmer1IS away from the number... 1 min
thanks mate
and after that i will be copying over the code because i have a dual channel dimmer for extraction and intraction on the grow. exaust hot air and intake of cold air
Yeah, Dimmer2
dont know if where you are i can say what i grow eheh
I am well aware when people avoid saying
π
well im not a dd. just a user that likes growing the best he can for his own happiness
do you use meters or feet?
is a 1mt1mt2mt height grow
is very small
it's not legal here, just "decriminalized"
here to, im in portugal
that hasn't changed much though
I lived in Rota for 2 years.. stationed there back in 97-99
but now people is starting to make such a problem, as a mater of fact is now plans for legalization but some bigpharma does not want the self growing
is like going to their pockets
yup
but im not paying like gold for some bad quality stuff when i grow biologically
no quems only bio ferts
im giving you so much work just for a bit of code..... π¦
and after we put the code right can I refer you on that portuguese forum i told you. Im not the brain behind so I think its good to give the right to the ones who own them
Ok, try this: payload: '{{value_json.Dimmer1[-2:]}}'
in the RX msg automation
Yeah, I don't have a source problem π
change on Fan Speed RX msg right?
yes
if you can listen in HA to topic # and let me see the speed change messages, that would be better
I feel like we aren't using the right json or topics, from what I've seen
payload is only on tx
on rx i only have value
how can i assist you with that?
teamviers
?
i clicked the phisical button a couple of times for you to see changes
if i made it with the HA button only shows the 0 or 100
this way you see dimming
Oh.. so there's no json, just the data
Ok, 1 min
sure. im not paying so i dont have right to expedite no one π
LOL
I just minimize this window
is a saying that we say in portugal
copy this?
1 sec.. that is wrong
this might work
- alias: Fan Speed RX msg
trigger:
platform: mqtt
topic: 'testepub'
action:
service: input_number.set_value
data_template:
entity_id: input_number.fan_speed_pct
value: '{{trigger.payload[-2:]}}'
will test
but it only senses 2 digit numbers right now
10-99
need to figure oout how to regex the number off the end
because you get a 1, and not 01, correct?
yes. but from 10-100 be good. 10% the fan motors does not even rotate
so you can make the input slider steps to 10
sorry 99
I understood
will see whats the minimum for each fan
the inline the minimum is arround 50% the big extractor I havent test that but since is the main temperature controller will be normally arround 60~70% (less is better, less noise!)
now it works, but how can i make the slider goes from 10 steps and the light icon from the button show on every time that is not 0?
the input slider you change the "steps"
how does that button even work?? Is it an mqtt switch?
can i use inicial as the normal sweet spot in terms of %
because the dimmer have a % control and a ON/OFF one
I see.. the mqtt light
when i set swith it goes off on his own and thats the way i found working
yeah I set the initial to 0 to prevent accidental movement. Habit.
if i know that 50% is the regular value it will start from there and only with human intervention will be changed
so when you turn it on, the R13_ON.. the mqtt light should see that and work properly.. but when you set it to 0... tha'ts not the same as R13_OFF
because with switch i was not abble to parse the message to have a feedback since the receiving message is the same of the % dimmer. just the command i send is diferenr
so the light stays on
no. it goes to 0 the same
so the fan shuts off, but the button is on
slider or button the message i receive is Dimmer1IS0
yeah, I don't know how to solve that
but messing with slider does not affect the button and vice versa
right
when the fan gets a ON, what does it do? Max speed or last set speeed?
ON means 99%
OFF 0%
full speed
but i would like the last set speed
and after that i can run a simple automation based on the temp and the hours that the HPS lamp is working and heating
make a template for 0 = off and 0 < ON
hummm can help out......
and how can i save the last set speeed
I will use the slider for ajustment and the button for on/off sensing
now when i click the button the slider goes to 99 but no 0 when i click again
to turn off
Oh... DERP..
1sec
is there a way of the ON button recall the last set speed instead of the ON-99 OFF-0 that i put?
light:
- platform: mqtt
name: "DIMMER1"
command_topic: "testesub"
payload_on: "R13_ON"
payload_off: "DIMMER1IS0"
optimistic: true
qos: 0
retain: true
i was about to put the code but is there a way of change "payload_on: "R13_ON"" for a slider last set speeed instead?
No, I think you'll have to modify the TX automation to use RM_ON as a trigger, then fire off a set mqtt DIMMER1IS(input_select)
make sense?
chinese
make sense now??? hahah
haa automate like the 3d printer fan
full blip at start then dimm
yeah, well...
blink right then π
is a term used by fw on marlin
eheheh
blip!
but the fan works though???
yes
ok.. let me look at the TX
I am eyeballing my 3d printer
it just changes the slider to 99.
Ok, paste back what you have
but when i turn off the slider remains at 99, but dimmer goes 0
the fan stops
ok, fix:
light:
payload_off: "DIMMER1IS0"
for DIMMER1
testing
so if the fan is off, and you send the %, what happens?
it starts again
at the % i set in slider
at that spedd or at 99? same as ON?
but im restarting now
so wee need to find out how to set the payload_on to be the DIMMER1IS%
now when i click off it stays on at 99%
oh damn
should it be changed in state_topic: instead
if the state is 0 then is off
I hoped when you clicked off, it would send Dimmer1IS0, but the slider needs to see 2 digits.. 10 -99
back to square one again......
well, that's a shitty dimmer
diy
present comapny excepted though LOL
1 atmega328p 1 weemos and robotdin 2ch
why would you choose that payload.. it's hard to work with
i cant choose i was following instrctions
i was not the programmer
so far you've been giving them
π
i made a armtronix dimmer with parts i have here
basicly i just copy the engennering
yes but mine is a dual and is not that finished product,. is more like a breadboard with 2 mcus and a dimmer ac
but yes same principle
controlling 220VAC
yep
so you have the actual project? there may be a much simpler way to skin this cat
yes
what part do you need the ESP or the atmega?
whatever is forming the mqtt message, so I gess the esp
this that we are doing is a fork right?
when we change stuff from other people github codes?
well yes
normally a fork is to republish also
if you think of the code like a tree
branches hummm get it
this is on an ESP8266??????????
wemmos
d1 mini
fuck i messed
same thing.. NOT the atmega.. so MEGs of memory.. why choose to do this withthe mqtt?
horrible design choices... anyway
yeah, I am reading that
I can rewrite the ESP side, but I am not touching the atmega.. we can send it back the serial it expects and the mqtt can be done easier.
This far exceeds the scope of #templates-archived though
sure
i get π
this is what make the obligation to go to 100?
else if (msgString.substring(0, 6) == "R14_ON" || msgString.substring(0, 11) == "Dimmer2:100")
under the hood, the ESP is doing what we would do in HA if (msgString.substring(0, 6) == "R13_ON" || msgString.substring(0, 11) == "Dimmer1:100")
{
Serial.println("Dimmer1:99");
#ifdef Dimmer_State
DimmerState1 = "99";
saveConfig() ? Serial.println("Dim val saved sucessfully.") : Serial.println("Dim val not saved");;
#endif //Dimmer_State
}
so it's already using the data internally and we need to unmuck it
just use the r14_on to trigger the dimmer100
right?
if im reading correcty is what is made in the original code
i know almost nothing about reading but common sensr
no, we don't need to use R14_OFF or ON
we can make it whatever we want
it's mostly common sense once you decode the language
DM me so we can move out of here since this isn't template stuff anymore
sorry i did not understand
IM me
DM/IM
got it
wondering if someone can have a look at this template data by copy + pasting it into the home assistant template tool
https://pastebin.com/kwJAq3kd
{% set my_json = [... see the pastebin above ...] %}
Find the raw value for id 5
eg. ID{{ my_json[3].id }} = {{ my_json[3].raw.value }}
{% for i in range(0, 30) %}
# if my_json[i].id == 5 then output my_json[i].raw.value
{% endfor %}
How was the trigger to state template again?
- data:
message: 'input_boolean.bed_ads_1x changed his status to {{ trigger.to_state}} '
service: notify.me
It's basically this i think, but the code has syntax errors that i can't figure out how to fix
{% for i in my_json %}
{% if my_json[{{ loop.index }}].id|int == 5 %}
my_json[{{ loop.index }}].raw.value
{% endif %}
{% endfor %
lol - how you get this json into HA? I guess thats way more then 255 characters
does HA have a limit on json size?
sensors have it
@snow zenith
https://community.home-assistant.io/t/solved-get-datas-from-json-file/162684/4
curl -s | jq .[].raw.value
you break the json into sensor attributes when you load it in
How you get the json in the first place
smartctl --json
so a file?
sensor:
- platform: command_line
name: smartctl_sdc_json
command: "/bin/cat /config/smartctl/sdc.json"
value_template: "{{ value_json.smartctl.exit_status }}"
json_attributes:
- smartctl
- device
- model_name
- user_capacity
- smart_status
- ata_smart_attributes
- power_on_time
- power_cycle_count
- temperature
ah neat
and then i parse them and store them in mqtt
got some help here - https://community.home-assistant.io/t/for-loop-within-json-table/193894/4
well when you go over the jq route you have a easy live π
`
$ cat json | jq .[].raw.value | jq -cs '{next: .[0], seccond: .[1], third: .[2], fourth: .[3]}'
{"next":2,"seccond":9358,"third":16495,"fourth":0} `
jq?
$single($, function($v) { $v.id = 5 }).raw.value
except i don't know how to put that into home assistant template, but I'll try read up on jq then
I also dont π
thats the right link btw
https://community.home-assistant.io/t/solved-get-datas-from-json-file/162684/4
you just cat out your file and let jq run over it - | jq .[].raw.value | jq -cs '{ value: .[5]}' ll probably do what you want
file: sdc.json = https://pastebin.com/77T3eCBh
ah! - wich part youre intrested?
ata_smart_attributes -> table
table:
id 5 -> raw_value
id187 -> raw_value (if exist)
id187 -> raw_value (if exist)
id 197 -> raw_value
id 198 -> raw_value
curl -s https://pastebin.com/raw/77T3eCBh | jq .ata_smart_attributes.table[].raw.value
and use then the -cs flag to create sensors out of the array
@snow zenith posted a code wall, it is moved here --> https://paste.ubuntu.com/p/jJtpjCdCyt/
the -cs flag can also create you more complex json afterwards
| jq '.data.monitors[] | { name: .lines[].name ,stop: .locationStop.properties.title, towards: .lines[].towards ,data: .lines[].departures.departure[].departureTime.countdown, trafficjam: .lines[].trafficjam }'| jq -cs '{name: .[0].name, stop: .[0].stop, towards: .[0].towards, next: .[0].data, seccond: .[1].data, third: .[2].data, fourth: .[3].data, trafficjam_0: .[0].trafficjam, trafficjam_1: .[1].trafficjam }'"
example
[
{
"id": 1,
"name": "Arthur",
"age": "21"
},
{
"id": 2,
"name": "Richard",
"age": "32"
}
]
JQ -> Find the name of the person who is 32 years old
cat json | jq '.[] | select(.age=="32")'
food time - good luck
Almost won
does anyone know how to make variables exist outside of a for loop
{% set var = "unknown" %}
{% for i in my_json %}
{%- if i.id == 5 %}
{% set var = i.raw.value %}
{% endif -%}
{% endfor %}
Answer is {{ var }}
{{ var }} works inside the loop, but it loses it's value outside of the loop
i think the answer is in here - https://jinja.palletsprojects.com/en/master/templates/#assignments
but its complicated
{% set ns = namespace(found=false) %}
{% for i in my_json %}
{%- if i.id == 5 %}
{% set ns.found = true %}
"{{ var }}"
{% else %}
{% endif -%}
{% endfor %}
{% if not ns.found %} "unknown" {% endif %}
^ solved.
nice - I came up with this now ```
cat json | jq '.ata_smart_attributes.table[] | { name: select(.id==5).name, id: select(.id==5).id, value: select(.id==5).raw.value}'
{
"name": "Reallocated_Sector_Ct",
"id": 5,
"value": 0
}
| jq '.ata_smart_attributes.table[]' | jq -c ' [.name, .id, .raw.value] '
["Raw_Read_Error_Rate",1,2]
["Spin_Up_Time",3,9358]
["Start_Stop_Count",4,16495]
["Reallocated_Sector_Ct",5,0]
["Seek_Error_Rate",7,0]
["Power_On_Hours",9,47777]
["Spin_Retry_Count",10,0]
["Calibration_Retry_Count",11,0]
["Power_Cycle_Count",12,7462]
["Power-Off_Retract_Count",192,602]
["Load_Cycle_Count",193,119393]
["Temperature_Celsius",194,32]
["Reallocated_Event_Count",196,0]
["Current_Pending_Sector",197,0]
["Offline_Uncorrectable",198,0]
["UDMA_CRC_Error_Count",199,0]
["Multi_Zone_Error_Rate",200,0]
That also worked
Only thing I would now like to do is that it is in another array
like this curl -s https://pastebin.com/raw/77T3eCBh | jq '.ata_smart_attributes.table[]' | jq -c '{.id, {name: .name, value: .raw.value}}' But apperantly quoting issues?
Posting here because I was in the middle of troubleshooting a json template for parsing an external api, when suddenly the sensor just no longer shows up at all. Stripped the config to everything but the basics for the sensor, but it wonβt come back. No errors in the log. Has anyone seen anything like this?
@shell lynx tryed a curl on the api endpoint?
@woeful loom try jq (thats almost always ma awnser aperantly π )
otherwise this meight be a good start https://en.wikipedia.org/wiki/Regular_expression
Sorry, Iβm kinda new to this. Do you mean trying a curl on the endpoint to make sure data is being given? If so, yes and the data is coming through. Just weird that the sensor stopped showing. Will try to revert to the last backup and see what happens.
thats right - just checking if ha can actually get data, API's can also change with a update
or maybe you renamed your file to something.yml
given a json output in mqtt of { "current-flow" : 10 } how do I access that in a template? It looks like it's taking the - in current-flow and trying to subtract it? value_template: "{{ value_json.current-flow / 10 }}" When I use the template tester under developer tools it tells me Error rendering template: UndefinedError: 'flow' is undefined
found the solution to my problem !!!!!!!!!!!!!
if you guys ever needs the siteId in rasspy intents
use {{ site_id }} it s a special slot
{{value_json['current-flow']}} @earnest arrow
How was the trigger to state template again?
- data:
message: 'input_boolean.bed_ads_1x changed his status to {{ trigger.to_state}} '
service: notify.me
rule 1 of templating
thanks. shows how much I use templates π€£
haha rule 1 is for @warm isle
?? Check your qoutes?
Templates can be tested via
> Templates
New members: Welcome?
aah - finaly found it 
Always checked the docks for... something
{{ trigger.to_state.state }}
@warm isle you also need data_template
ah! thx!! - been so long out of the HA configuration that i forgot that
Hey guys is there anyway to test templates outside of the dev tools
I see hass-cli template but I don't know it this works? I tried feeding a file to it and see if it rendered something, but nothing
why?
Just checking/testing. The following is in my sensors.yaml and noting is created. Am I off somewhere? - platform: rest name: simple_test resource: https://jsonplaceholder.typicode.com/posts/42
To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks. Here's an example:
```
code here
```
Watch the animated gif here: https://bit.ly/2GbfRJE
DO NOT repeat posts. Please edit previously posted message, here is how -> https://bit.ly/2qOOf1G
anything in the logs? did you run a config check and restart home assistant?
yes, config check is clean, and nothing in the logs. This is just a sample. I had a similar one that was working yesterday, and it just stopped.
do you see it at developer tools > states?
also this is more of an #integrations-archived question
no, that's where i normally look for it. Yesterday, it was there just fine. I restored from a backup from yesterday (just before I added the code), re added, and still nothing
got it, thanks for that. Wasn't sure where to post.
I posted here because i was trying to figure out the template for parsing when it all went away
π
Does anyone know if input booleans will keep their state over a HA restart?
By default, yes
not if you have initial: setting. then it will default to that state.
If you want the input_boolean to maintain and restore state, remove initial: attribute where you define it.
that is wierd, i have an input boolean that has no initial setting. I set an automation to turn on that boolean when HA shuts down, so I have an indicator if I had a clean shutdown. Unfortunately the boolean will not be turned on after I restart HA.
@nimble hinge In general, you can write and test template code in the command line. without hass-cli but you may not have access to the hass objects, states. try something like```
$ python3
from jinja2 import Template
s = "{% for element in elements %}{{loop.index}} {% endfor %}"
Template(s).render(elements=["a", "b", "c", "d"])
1 2 3 4Template("{{ var }}").render(var=25)
'25'Template("{{ var }}").render(var="hello world!")
'hello world!'
hello, if I read api data in with ```
- platform: rest
name: lenfant_trains
resource: 'https://api.wmata.com/StationPrediction.svc/json/GetPrediction/E05?api_key='should I be able to access the data with this: - platform: template
sensors:
lenfant_length:
value_template: '{{ state_attr('sensor.lenfant_trains', 'Trains')[0]["Car"] }}' ```
I'm getting an error that sensor.lenfant_trains is undefined
Does sensor.lenfant_trains exist in
-> States?
Does it have an attribute Trains (not trains)?
it does not (thought it did) exist it states
There you go...
thanks!
ok, i got sensor.lenfant_trains back in states by changing the first block to ```
- platform: rest
name: lenfant_trains
resource: 'https://api.wmata.com/StationPrediction.svc/json/GetPrediction/E05?api_key='
value_template: '{{ value_json.Trains[0]}}' ```and i get 'expected <block end>' error right at the value_template
{"Trains":[{"Car":"6","Destination":"SilvrSpg","DestinationCode":"B08","DestinationName":"Silver Spring","Group":"1","Line":"RD","LocationCode":"A01","LocationName":"Metro Center","Min":"3"} that's the payload
@shell lynx That's not a valid JSON payload. You are missing a square bracket for the array and the closing curly brace in the end. This is the valid JSON {"Trains": [{"Car": "6","Destination": "SilvrSpg","DestinationCode": "B08","DestinationName": "Silver Spring","Group": "1","Line": "RD","LocationCode": "A01","LocationName": "Metro Center","Min": "3"}]}when I try the following in the template editor, it works: ```
{% set value_json = {"Trains": [{"Car": "6","Destination": "SilvrSpg","DestinationCode": "B08","DestinationName": "Silver Spring","Group": "1","Line": "RD","LocationCode": "A01","LocationName": "Metro Center","Min": "3"}]} %}
{{ value_json.Trains[0] }}
ok, thanks. so a template to get "Cars" would look like: ```
- platform: template
sensors:
lenfant_length:
value_template: '{{ state_attr('sensor.lenfant_trains', 'Trains')[0]["Car"] }}' ``` because i'm getting the 'expected <block end>' error with that
I think it was just a paste error. I can read the actual jason with value_template: '{{ value_json.Trains[0].Car }}' I guess I just don't understand when to use value_json over state_attr
Thanks for your collective help and patience. switching to value_json is going to work.
Is there any way to call in a value of a template into a card's attribute? for example:
cards:
- entity: sensor.md_srv_media_data_free
max: [TEMPLATEVALUE]
min: 0
type: gauge
I want the "max" to be the sum of 2 sensor's value, which is done in the template. I'm not sure if this is the best approach, so I'm open for any idea. Thanks
No, stock cards don't support templates
I see. So I'm guessing there is no way to have a dynamic variable there
Nope
That'd be down to the custom card supporting it
@woeful loom posted a code wall, it is moved here --> https://paste.ubuntu.com/p/kmTwzv5rDs/
@woeful loom posted a code wall, it is moved here --> https://paste.ubuntu.com/p/4BKDjrDnWP/
How do I handle a **nested **JSON response from a RESTful sensor.
I want to end up with 4 sensors, duration and risetime each array member.
The only way I seem to be able to get them is by running the REST twice, once with
json_attributes_path: "$.response[0]" and once with
json_attributes_path: "$.response[1]".
This is working well, but I don't want to add to the resource server workload by running two calls when one should do.
Surly I should be able to extract what I want from one REST call.
The REST call works well and returns a response that is an array of two.
The first one, response[0] has two values, duration and risetime.
Obviously the second one, response[1] also has duration and risetime.
I did try to post the REST output but fell foul of the code wall bot - my mistake, never used Discord before.
@woeful loom I think i do that by parsing the rest call sensor with a template sensor to extract out each field i care about
- platform: rest
name: Frigate Debug
resource: http://192.168.x.x:5000/debug/stats
scan_interval: 5
json_attributes:
- front
- coral
value_template: 'OK'
here's the nesting being handled by the template sensors
sensors:
front_fps:
value_template: '{{ states.sensor.frigate_debug.attributes["front"]["camera_fps"] }}'
unit_of_measurement: 'FPS'
front_skipped_fps:
value_template: '{{ states.sensor.frigate_debug.attributes["front"]["skipped_fps"] }}'
unit_of_measurement: 'FPS'
could someone assist me in making a template for my d-link swtich to get the watt useage into HA
this is what i have so far
platform: template
current_power_w:
friendly_name: Drier Power useage"
value_template: "{{ state_attr('switch.d_link_smart_plug_w215', 'current_power_w')|int }}"
unit_of_measurement: 'w'```
let me know what have buggered ta
@balmy moth indentation is wrong
Everything below current_power_w: needs to be indented two spaces
platform: lastfm
api_key:
users:
- DH4774
platform: template
current_power_w:
friendly_name: Drier Power useage"
value_template: "{{ state_attr('switch.d_link_smart_plug_w215', 'current_power_w')|int }}"
unit_of_measurement: 'w'
switch:
platform: dlink
use_legacy_protocol: true
host: 192.168.1.111
username: admim
password: x```
that?
Oh you need to change platform: to - platform:
both?
so 2 indents then - followed by platform:
- platform:
- platform: lastfm
api_key: x
users:
- DH4774
- platform: template
current_power_w:
friendly_name: Drier Power useage"
value_template: "{{ state_attr('switch.d_link_smart_plug_w215', 'current_power_w')|int }}"
unit_of_measurement: 'w'
switch:
- platform: dlink
use_legacy_protocol: true
host: 192.168.1.111
username: admim
password: x```
current_power_w:
^```
Everything below
current_power_w:needs to be indented two spaces
@buoyant pine odd after doing this it still isnt working
- platform: lastfm
api_key: x
users:
- DH4774
- platform: template
current_power_w:
friendly_name: Drier Power useage"
value_template: "{{ state_attr('switch.d_link_smart_plug_w215', 'current_power_w')|int }}"
unit_of_measurement: 'w'
switch:
- platform: dlink
use_legacy_protocol: true
host: 192.168.1.111
username: admim
password: x```
indentation is still off and you're missing part of the template sensor config, one sec
- platform: lastfm
api_key: x
users:
- DH4774
- platform: template
current_power_w:
friendly_name: Drier Power useage"
value_template: "{{ state_attr('switch.d_link_smart_plug_w215', 'current_power_w')|int }}"
unit_of_measurement: 'w'
switch:
- platform: dlink
use_legacy_protocol: true
host: 192.168.1.111
username: admim
password: x```
yeah you fixed the second part but you're still missing sensors: in the template sensor config
(didn't see that in your original post)
the what?
and if it cant be counted on to verify yaml why is it there?
the little green tick at top of file editor
i run core only so i don't have addons but i think that just verifies that it's valid YAML, not necessarily that it's a valid config
extra keys not allowed @ data['current_power_w']. Got OrderedDict([('friendly_name', 'Drier Power useage"'), ('value_template', "{{ state_attr('switch.d_link_smart_plug_w215', 'current_power_w')|int }}"), ('unit_of_measurement', 'w')]). (See ?, line ?).
im this close the throwing the bloody thing in the bin and buying something else
share it again
- platform: lastfm
api_key: nein
users:
- DH4774
- platform: template
sensors:
current_power_w:
friendly_name: Drier Power useage"
value_template: "{{ state_attr('switch.d_link_smart_plug_w215', 'current_power_w')|int }}"
unit_of_measurement: 'w'
switch:
- platform: dlink
use_legacy_protocol: true
host: 192.168.1.111
username: admim
password: lolno```
lol... it'll take time but it'll eventually click
one tip. if you have something like
word:
``` anything below that that's related to it will need to be indented two spaces
so for example:
- platform: template
sensors:
current_power_w:
friendly_name: Drier Power useage"
value_template: "{{ state_attr('switch.d_link_smart_plug_w215', 'current_power_w')|int }}"
unit_of_measurement: 'w'
current_power_w: is related to sensors: so it's indented two spaces
just like friendly_name, value_template, and unit_of_measurement are related to sensors:
so they are also indented
i suppose, but that wouldn't be valid
last thing how do i give it a icon like a power meter?
are you going to use this in a card in the frontend?
yes
you can specify the icon in the card
mdi:name-of-icon from the list here: https://cdn.materialdesignicons.com/4.7.95/
do i need to go into code editor?
Entities Card Configuration
hey guys, i'm new to Home assistant and i got some problems... can sb. help me out?
@grand lake dont ask to ask, just ask pal π
so i got digital led's (WS2811) connected to an esp8266 and try to control it via home automation - i'm following this outdated guide :https://github.com/bruhautomation/ESP-MQTT-JSON-Digital-LEDs
i have problems with the config
is there a better way to control digital led's?
How to setup the config so that everything works? i got mqtt set up and connected, esp running properly - just not the config yet
@grand lake try wled firmware
@woeful loom posted a code wall, it is moved here --> https://paste.ubuntu.com/p/9zZd83bgNC/
~codewall @woeful loom
@woeful loom Rule #6: Please do not post codewalls (longer than 15 lines) - use sites such as https://hasteb.in/, https://paste.ubuntu.com/, or others.
Please take the time now to review all of the rules and references in #rules.
~codewall @woeful loom
@arctic sorrel I understand about the code wall so I tried to get below the 12 lines or whatever I read was OK. But I just don't know how to explain my question. I see other postings with small blocks of code so is there somewhere else I should be posting or should I not mark it as code? - I've only been on discord a few days an don't feel comfortable upsetting things.
The problem was the total number of lines you posted in one hit - that's unpleasant for those on mobile/with larger text/smaller screens
So, if you're going to most more than a dozen lines, move all the code out to a code share site
Thanks for explaining that, I'm not familiar with code sharing sites, I'll try and see what others have done. I'm close to giving up anyway, at my age I'm too old to learn new tricks :-(
@arctic sorrel
You're never too old π
json_attributes:
- next_one # I made this up as array didn't have a label
- plus_one # # I made this up as array didn't have a label
``` you can't make things up π
Instead try
iss_duration_test1:
value_template: '{{ states.sensor.iss_passtimes_test.attributes[1]["duration"] }}'
iss_rise_test1:
value_template: '{{ states.sensor.iss_passtimes_test.attributes[1]["risetime"] }}'
iss_duration_test2:
value_template: '{{ states.sensor.iss_passtimes_test.attributes[2]["duration"] }}'
iss_rise_test2:
value_template: '{{ states.sensor.iss_passtimes_test.attributes[2]["risetime"] }}'
``` (or maybe `[0]` and `[1]`)
68 with conative issues, I used to be Microsoft Certified years back, can't even write a batch file now. Oh that suggestions looks promising. Off to try - I really do appreciate it.
No worries, and hey, you're trying - that's more than many younger folks π
Agreed. Good luck and keep at it. It'll click.
Thanks guys, it was so obvious using the array index, but it didn't work out, I tried [0] & [1] and also [1] & [2].
I hope this isn't going to code wall, but this is the output of the API call, does it look like it should work?
{
"message": "success",
"response": [
{
"duration": 557,
"risetime": 1589066522
},
{
"duration": 647,
"risetime": 1589072250
}
]
}
All four states are "unavailable" π¦
The sensor should have a bunch of attributes already?
Actually ... https://www.home-assistant.io/integrations/iss/
But, there, your JSON would require .response[0].duration etc
You can test in
-> _Templates
It's a long story, but in essence, the ISS sensor doesn't work correctly for people in the UK. I spent weeks on it, and lots of others in the UK had the same issue. The sensor would trigger when the ISS was over a completely different continent. The HA MAP would show my home zone in the correct place, it would show the ISS over, let's say, India, and NASA also showed it over India, but the sensor would go true. At other times, the map and NASA would show it over my house, and I could see it with my own eyes, but the sensor would stay false. So I gave up and that is why, my friends, I made the RESTful sensor. It works perfectly, shows me when the next two passes are, how long to wait for the next one, how long before I would lose radio contact and the distance between the ISS and me (ground track of course).
Yes, I use the Templates page all the time, it's been a god-send.
So all this present work (14 days and counting), and the reason I'm here, is to reduce two REST calls to one!
It's not that I just want a solution handed to me, I want to understand how it works.
Ah, cool π
hey all π i m having trouble with a template ( again )
- service: 'mqtt.publish'
data:
payload_template: '{"intentFilter": "Again", "sessionId": {{session_id}}, "customData": {{volume}} }'
topic: 'hermes/dialogueManager/continueSession'
retain: true- service: 'persistent_notification.create'
data_template:
message: '{{session_id}}'
- service: 'persistent_notification.create'
the mqtt published is:
{"intentFilter": "Again", "sessionId": , "customData": }
the variables are not passed :/
tryed to escape the first and last {
but not working
Well your first one fails rule 1 of templating
Become a real Jinja2 Ninja! Don't worry my Genin, we are here to help! You can find the docs at https://www.home-assistant.io/docs/automation/templating/ - and don't forget rule #1! Please use https://www.hastebin.com/ or https://paste.ubuntu.com/ to share code or logs
just made it work hehe thank you π i did forgot the _template for data
data_template instead of data
thank you @dreamy sinew
Hi. I got this intergration which provides about my houses power usage for the preceding day. I get 24 sensors. One showing usage for each time slot. The sensor got a 'metering date' attribute. I'd like to display this as a graph. What would you recommend for processing the sensors?
I had this idea to associate the value with it's attribute (metering date) and not the actual time of storing the data in the database
But I'm not sure how to
Is it possible to use a variable to construct a sensor name?
like
{{ states.sensor.my_sensor_{{ now().hour }} }}
Possible, depends on where you're using it though
as a value_template in a template sensor
Then it will never update
Why not?
What can I do, if I want my template sensor to retreive data from a specific sensor, based on a variable?
a large if-else statement?
Is something like this possible?
value_template: >-
{%
{% now().hour == 0 %}
{{ states.sensor.eloverblik_energy_22_23 }}
{% now().hour == 1 %}
{{ states.sensor.eloverblik_energy_22_23 }}
{% now().hour == 2 %}
...
{% now().hour == 23 %}
{{ states.sensor.eloverblik_energy_23_24 }}
{% endif %}
%}
Maybe? I'm not sure if that'll work either
Hey there having some issue with templating:
If I enter:
{{ relative_time(states.input_boolean.washing_machine_full.last_updated) }}
{{ now() }}
{{states.input_boolean.washing_machine_full.last_updated }}
I am getting
21 minutes
2020-05-11 00:21:31.646520+02:00
2020-05-10 21:59:57.682981+00:00
It looks like the first result is minutes from midnight instead of the last_updated
Anyone knows why ?
Oh just realize UTC vs local time
sorry π
What does 'OK' symbolize in value_template: 'OK' ?
Is this supposed to cause an error?
- service: light.turn_on
entity_id:
- light.kitchen
data_template:
brightness: {{255 if states("sensor.time_of_day") == "Evening" else 30 }}
the template is valid according to the template editorr
otherwise i get an ordereddict invalid key error
put the entity_id in the data_template
Need to wrap the template in '
even if its a number?
entity_id needs to be inside data_template? it worked the this way if i hardcoded brightness to 20
brightness: "{{255 if states("sensor.time_of_day") == "Evening" else 30 }}"
``` this causes an error
- service: light.turn_on
data_template:
entity_id: light.kitchen
brightness: {{30 if states("sensor.time_of_day") == "Evening" else 255 }}
``` same error
- service: light.turn_on
entity_id:
- light.kitchen
data_template: >
brightness:
{% if is_state('sensor.time_of_day', "Evening") %}20{% else %}100{% endif %}
this works but its so verbose
- service: light.turn_on
entity_id:
- light.kitchen
data_template:
brightness: >
{% if is_state('sensor.time_of_day', 'Night') %}20{% else %}255{% endif %}
``` this is the only thing that seems to work
unless i'm going crazy, thanks babichajacob & phnx π
Will work if you put single quotes on the outside like phnx said
"{{ }}" if you have single quotes inside the braces, '{{ }}' if you have double quotes inside the braces (though common convention is the first one)
oh snap you're right, this worked:
entity_id:
- light.kitchen
data_template:
brightness: '{{255 if states("sensor.time_of_day") == "Evening" else 255 }}'```
thanks π
No prob, single-line templates always need to have quotes on the outside
Trying to use the template editor, but not grasping the basics - have a sensor called: sensor.greenhouse_humidity, I can see this has a value in the states tab, I've tried putting : {{sensor.greenhouse_humidity}} in the template editor, but get a 'Error rendering template: Undefined Error: 'sensor' is undefined' error? Can anyone give me a quick pointer?
Become a real Jinja2 Ninja! Don't worry my Genin, we are here to help! You can find the docs at https://www.home-assistant.io/docs/automation/templating/ - and don't forget rule #1! Please use https://www.hastebin.com/ or https://paste.ubuntu.com/ to share code or logs
Have a look at the templating docs, particularly https://www.home-assistant.io/docs/configuration/templating/#states
{{ states('sensor.greenhouse_humidity') }}
Ah useful - thanks! I'd read that page, but missed the part in highlights..... π€¦ββοΈ
Hi All, I am using a value_template in an automation to change my light colors based on the holiday, how can I put and and in this. {% set n = now() %} {{ n.month == 5}} so that I can do it for more than one month? like lets say I wanted May and July to be in the same automation
Use and
its that easy?
can I use multiple ands in the same line like {{ n.month == 5 and n.month == 7 and n.month == 8}}
Yup
perfect, thank you. I didnt know of a way to force HA to check for that month to see if it works.
You can simply use now().month. No need to set variable.
oh, well that would have been a little easier.
Can anyone point to documentation on the use of speech marks, quotes etc in yaml files? I can see there's some sort of convention and would like to understand why you add them, why you don't, why you use doubles, singles etc this works, but I don't know why...!
where: '"device" = ''Greenhouse'''
measurement: '"BrynyneuaddSensors"'
value_template: {{ states('sensor.greenhouse_humidity') | round(1) }}
field: Temperature
Eg why speech marks AND quotes around the measurement, why do some examples have single quotes around the value_template and others don't - why no quotes needed around 'temperature' etc!
@velvet glen it has nothing to do with Home Assistant. It is how YAML is structured. It is usually best practice to surround values with quotes. If the value has quotes in it, you need to escape those. When you use in-line templates, you are required to put the code in quotes - like ```
value_template: "{{ states('sensor.greenhouse_humidity') | round(1) }}"
Great explanation - thanks, crystal clear!
hey anyone has an idea i have an RF sensor on my postbox outside (its an metal one but my RF bridge is near and luckly it works)
so it sends telegram now that there is post
using this:
- alias: Receive RF Briefbus
trigger:
platform: event
event_type: sonoff.remote
event_data:
name: Briefbus
action:- data:
message: Er is post!
service: notify.telegram
- data:
in automatisation
is it possible to create a Card (postbox for example)
that shows for a day the times when there was delivered something?
for example just a list:
Briefbus
9u32
11u23
14u33
so i see it directly without much clicking π
Probably a super simple one, but what's the easiest way to check if now() >= a certain time?
In an action or a condition, or a trigger?
Hmm, to be used as a condition I guess. true/false response. For a bayesian sensor.
Yeah, saw that. Just needed the comparison logic and converting time string to time object. Looks like those docs will do the trick, thanks!
Am I safe to just wrap a not() around an is_state to invert it?
{{ not is_state('binary_sensor.asleep','on') }}
First template-driven bayesian sensor with 8 observations done. Some whacky logic in there!
Wow, the display of observations for templates in the entity is... less than ideal.
Instead try
iss_duration_test1: value_template: '{{ states.sensor.iss_passtimes_test.attributes[1]["duration"] }}'
@arctic sorrel
I've solved it at last, so easy when the penny dropped, had to add one more level - thanks for your patience:
value_template: '{{ states.sensor.iss_passtimes_test.attributes[response][1]["duration"] }}'
@small rock posted a code wall, it is moved here --> https://paste.ubuntu.com/p/Fcnwrwfr58/
The question: I'm missing something: not a valid value for dictionary value @ data['entity_id'] for https://paste.ubuntu.com/p/Fcnwrwfr58/
Don't need -
In front of media_players
And your logic won't work, needs one full if, elif, else, end
How could i do It then?
You'll need to use trigger.entity_id
trigger isn't possible it's part of a bigger script
Strip the - out of the entity lines
Your entity isn't - media_player.banana but media_player.banana
Not entirely sure you can do a list like that though
I have removed the '-' and still giving issues ... Here is the complete script: https://paste.ubuntu.com/p/384sQKvBtb/
I don't think you can do multiple entities like that
The idea is to pause mopidy or spotify entries, play tts and then resume
Your automation can still send the trigger.entity_id
Would this be the right channel to ask about a Utility Meter sensor making problems? π
@phdelodder how are you running this, clicking each script manually?
Just break out into each entity into it's own template
data_template:
entity_id: >-
{% if is_state('variable.spotify_isabel', "True") %}
- media_player.spotify_isabel
{% endif %}```
so you would have 4 of those for each of your media players
and variable.
often they are false so the script fails
But hey I'll split it up even more
Can I use a script variable in a template eg: {% if is_state('variable{{script_variable}}', value) %}
might have to | int it as it will probably come over as a string
@brisk temple https://paste.ubuntu.com/p/GDnQKtwygP/
π
your condition will stop the script from continuing if first user is not true so it won't run the others
short question (i hope π ): Why is this not working?
action:
service: light.turn_on
entity_id:
- light.1e_garderobe_test_lamp
data_template:
brightness: >
{% set grens = states('input_number.lumen_grens_buiten')|int %}
{% set lumen = states('sensor.voortuin_deur_multisensor_illuminance')|int %}
{% if lumen < grens %}
"{{states('input_number.1e_garderobe_plafond_licht_sterkte_in_de_ochtend_in_de_avond')|int}}"
{% else %}
"{{states('input_number.1e_garderobe_plafond_licht_sterkte_overdag')|int}}"
{% endif %}
Could it be that this Template reset itself with HA restart?..
{{ as_timestamp(states.binary_sensor.dryer_on.last_changed) | timestamp_custom('%d/%m %H:%M',True) }}
It produces this error: Invalid data for call_service at pos 1: expected int for dictionary value @ data['brightness']
"{{states('input_number.1e_garderobe_plafond_licht_sterkte_in_de_ochtend_in_de_avond')|int}}"
``` π€
See the "? Bin them π
Same for the other line
You're carefully turning your state into an int, and then into a string
Damn, I thought I tried that... You're a life saver again! Thanks!
Hi, for a Template Switchβs power_on action, is it possible to call multiple services please?
switch:
- platform: template
...
turn_on:- service: switch.first
data ... - service: switch.second
- service: switch.first
Is this possible?
I'm pretty sure you'd need to use a script for that
I just tried it and it didnt complain about the config. Seems to be working but need to test thoroghly as both actions are backups for each other and its hard to tell if both worked