#templates-archived

1 messages · Page 96 of 1

warm isle
#

My issue is that I can't think of a good solution.
Maybe a while loop?

silent barnBOT
#

@warm isle The XY problem is asking about your attempted solution rather than your actual problem. This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.
The problem occurs when people get stuck on what they believe is the solution and are unable to step back and explain the issue in full.

ivory delta
#

We have no idea what you're trying to solve.

arctic sorrel
#

You're not telling us anything about what you're trying to achieve

#

Just ... vague hints about dimming

warm isle
#

Have to get back to it later this evening. Birthday party incoming. Wasted already to much time (and energy) to it 😅

lilac dust
#

does anyone know how i could get this working:

  • platform: mqtt
    name: "BlueIris"
    state_topic: "BlueIris/status"
    command_topic: "BlueIris/admin"
    payload_on: "profile=1&lock=1"
    payload_off: "profile=5&lock=1"
    state_on: "profile=1"
    state_off:
    • condition: template
      value_template: "{{ not is_state('sensor.blueiris_profile', 'profile=1') }}"
      optimistic: true
      qos: 0
silent barnBOT
#

@lilac dust 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

lilac dust
#

the templating doesnt work

arctic sorrel
#

And remember that over 15 lines you must use a code share site...

#

What is that?

#

Switch? Sensor? Cover?

lilac dust
#

switch

#

with a state from mqtt

arctic sorrel
#

Where did you se that it supports a template for the off state?

lilac dust
#

nowhere, hence the question

arctic sorrel
#

Well... then you can't

lilac dust
#

ok, thats to bad

arctic sorrel
#

(string)(Optional)

lilac dust
#

any other idea how i should go about this?

lilac dust
#

ok so value template is the right way after all?

arctic sorrel
#

A valid configuration is the right way

#

There's no condition in there

#

You also still need to set the state_off string

lilac dust
#

ok, then i need to do it some other way

arctic sorrel
#

Or just

      value_template: "{{ 'profile=1&lock=1' if is_state('sensor.blueiris_profile', 'profile=1') else 'profile=5&lock=1' }}"
``` and don't set either `state_on` or `state_off`
#

Assuming your sensor returns those exact states

lilac dust
#

it does, but there can be 7 different states, one of them is ON

arctic sorrel
#

So?

#

Please test the above template 😉

#

Hell, please read the logic

lilac dust
#

will do, and i have tried reading i just dont get it - sorry

#

i will try your suggestion, just a sec

arctic sorrel
#

Pseudo-code:

if sensor.blueiris_profile is 'profile=1'
  return 'profile=1&lock=1'
otherwise
  return 'profile=5&lock=1'
#

The first is your defined on payload (default for the on state)

#

The second is your defined off payload (default for the off state)

#

So, if that sensor is 'long=john' then it'll return the off state string

lilac dust
#

Invalid config for [switch.mqtt]: value should be a string for dictionary value @ data['state_off']. Got [OrderedDict([('condition', 'template'), ('value_template', "{{ 'profile=1&lock=1' if is_state('sensor.blueiris_profile', 'profile=1') else 'profile=5&lock=1' }}")])]. (See ?, line ?).

arctic sorrel
#

Then you messed up your indenting

#

Or something else

silent barnBOT
arctic sorrel
#

☝️

lilac dust
arctic sorrel
#
    - condition: template
``` ![blink](https://cdn.discordapp.com/emojis/709124808297807984.webp?size=128 "blink")
#

Please stop making stuff up

#

As I said and as you found - there is no such option

#

I didn't say just replace that template - I said a lot more

lilac dust
#

yes you did but unfortunately thats what i understood

#

the value template, how should i use it?

arctic sorrel
#

Step one: define state_off

#

Step two: remove that damn line

lilac dust
#

your line?

arctic sorrel
lilac dust
#

its state off im trying to define

arctic sorrel
#

No

#

You're banging the rocks together and hoping for fire

lilac dust
#

yupp!

arctic sorrel
#

You also still need to set the state_off string

#

Just like you did for state_on

lilac dust
#

ok but the state_off can have more than one value

arctic sorrel
lilac dust
#

it can have six diffrent values

arctic sorrel
#

Two people... separated by a common language

lilac dust
#

well, to be fair: this isnt my language...

#

Got it working - Thanks

#

never tried templating before

versed tide
buoyant pine
#

Fixed in 0.112.1

versed tide
#

Oh, updates so fast. 🙂

hollow bramble
#

Ha that’s funny . Doctor Cox is actually the character that I imagine Tinkerer as most often, except with a Glaswegian accent

dull ledge
#

How would I set a variable to the value of the state_attr I'm pulling?

{% set current_date = now().strftime("%Y-%m-%d ") %}
{{ current_date }}
{{ state_attr('weather.kelp_daynight', 'forecast')[0].datetime }}
hollow bramble
#

The same way you set it the first time

#

set variable =

dull ledge
#

ah whoops. I tried keeping the {{}} within the statement

buoyant pine
#

@hollow bramble absolutely

dull ledge
#

Dr. Cox = I'm gonna love the shit out of you and help you in everything you do. But I'm gonna make you feel like a complete and total idiot while I do it. Ya got that newbie?

hollow bramble
#

Pretty accurate 🤣 earned respect is necessary to get rid of that last part

dull ledge
#

well. I needed to get mad jinja skills for work. So this is good practice

#

in jinja do I need to set an empty variable outside of a for loop so that after setting it in the for loop it still exists outside of said loop?

hollow bramble
#

The problem you may run into is custom functions are going to be different

#

You need to put it in a namespace for that

#
{% set ns = namespace(entity_id="") %}
{% for switch in states.switch %}
{% if switch.name | lower == whatever_the_name_is | lower %}
{% set ns.entity_id = switch.entity_id %}
{% endif %}
{% endfor %}
{{ns.entity_id}}
#

example

dull ledge
#

cool. thanks

#

how do I say tomorrow?
now().strftime("%Y-%m-%d ")

#

will now() + 1 work?

hollow bramble
#

that should be easy enough to google 😉

dull ledge
#

I am

silent barnBOT
dull ledge
#

i thought the limit was 15 lines. lesigh

#

any tips for improvements on that?

#

other than remove the extra print statement

arctic sorrel
#

It is 15 lines

#

That was 18 lines of text

dull ledge
#

ah. I thought it only counted what was in the code block. My mistake

ivory delta
#

It counts everything so we don't have to look at a wall of text.

dull ledge
#

found one issue. It was going to break on saturdays.

#

{% if forecast_day == tomorrow or (tomorrow == 0 and forecast_day == 0) %}

dull ledge
fading stratus
#

trying to set up an automation for some of my LEDVance tunable white bulbes to turn on to the right color depending on the time of day. I wound up using the custom compponent hass-variables. I know that light_temp.state is set to 3500 right now. My automation is turning the lights on with kelvin: '{{ light_temp.state | int }}' but I am getting an error: expected int for dictionary value @ data['kelvin']

dreamy sinew
#

Sounds like a rule one of templating violation

silent barnBOT
dreamy sinew
#

There it is

silent barnBOT
hollow bramble
#

it's also there 😉

fading stratus
#

well, wish I found that page sooner. Thanks!

dull ledge
#

thanks for the help i got here. Here is my 2 day forecast to use in appdaemon

dreamy sinew
#

Woof

queen meteor
#

That looks so repetitive repetitive repetitive

hollow bramble
#

Input number

winged dirge
#

Ok fe

hollow elm
#

Hi Guys, I'm trying to setup a air quality monitor based on arduino but I'm havo no developer skills. Thus, I'm having a lot of difficult to create an entity sensor based on the information received in the broker (I know, shame on me)>

#

Anyone available to review it for me?

  name: "Air Quality"
  state_topic: "home/gasleak"
  value_template: >- 
          {% set value = {{value_json.measure}} %}
          {%- if value < '100' -%}
          Good
          {% endif %}
          {%- if '100' < value < 130-%}
          Attention
          {% endif %}
          {%- if value > 130-%}
          Danger
          {% endif %}```
#

Thank you!

#

The information arrived in the topic this way:
{"value":"81","Status":"Ready"}

little gale
ivory delta
#

What have you tried?

#

You always seem to want other people to do all the work 🤷‍♂️

#

You haven't even said where that data comes from. Is it a sensor? A webpage?

little gale
#

A sensor

#

I can't parse it tbh

#

What's the syntax again for set = in the template editor for JSON?

ivory delta
#

What kind of sensor is it?

little gale
#

Command Line sensor

ivory delta
#

Do you know the difference between a Dict and a List in Python?

little gale
#

I do not.

ivory delta
#

They're both simple. Read it, understand it. It'll help you with templates so you don't have to ask other people to do simple things every time.

#

It doesn't matter what your data looks like, it'll always follow the same pattern.

hollow river
#

@hollow elm what error message are you getting that makes the code you have a problem?

little gale
#

How do I test the JSON data in the template editor?

ivory delta
inner mesa
#

Google has the answers to a lot of these questions. Just first type them exactly into Google, come back with questions

lyric sun
#

Message malformed: invalid template (TemplateSyntaxError: Encountered unknown tag 'mapper'.) for dictionary value @ data['sequence'][0]['data_template']['source']

#

seems to be the multiline part in source:

#

found it... was missing the "set" before the mapper

fallen sorrel
#

Hi Guys,.. battling my own lack of yaml formatting knowledge,.. and what the error messages are telling me,... Component error: sensors - Integration 'sensors' not found. Component error: time_of_day - Integration 'time_of_day' not found. Invalid config for [sensor.template]: [time_of_day] is an invalid option for [sensor.template]. Check: sensor.template->time_of_day. (See ?, line ?). Component error: sensors - Integration 'sensors' not found. Component error: time_of_day - Integration 'time_of_day' not found. https://pastebin.ubuntu.com/p/jr56ycn7fB/

#

I cannot seem to work out whether I need a sensor entry or sensors,.. even though I use

#

- platform: entry

arctic sorrel
#

There is no sensors integration

fallen sorrel
#

vscode says its happy,.. but alass HA has other ideas...

arctic sorrel
#

Well, yes 😉

buoyant pine
#

It's sensor: not sensors:, and you can only have one sensor: key

arctic sorrel
#

Follow the docs exactly and don't make stuff up 😉

buoyant pine
#

And every sensor platform can go under that (or use the second method linked above)

fallen sorrel
#

confused,.. so why are these entries not in the sensor.yaml file,.. or can they..

arctic sorrel
#

You've commented out the line that would use that file

#
#sensor: !include yamlconf/sensors.yaml
fallen sorrel
#

ok,.. so I have removed the sensors: entry,.. but then vscode says missing property "sensors", and property 'time-of-day' not allowed..

#
  time_of_day:
    value_template: >
      {% if states.sun.sun.state == 'above_horizon' and as_timestamp(now()) < as_timestamp(states.sensor.date.state ~ ' 12:00:00') %}
        morning```
silent barnBOT
#

Always run the configuration check command when you make changes. Don't trust the UI check - it misses some problems.

arctic sorrel
#

Ignore VSCode, trust that

#

Which currently it doesn't

fallen sorrel
#

tx guys,.. let me play some more the checker is a new tool to play with,.. and the yes vscode checker is not reliable I have decided...

fallen sorrel
#

the online tester seems good,.. at least it gives some more meaningful output unlike VS,... and I can now play and break things to see what is reported,... just updated to 112.2,... and the tools=> template has changed,... and I now have my 'time-of-day' as a service,... ( more to play with,...) so I now have a 'sensor:' device called 'time-of-day',.. so what is a sensors: within that entity...? where do I find the docs on that pls... Tx again one and all

little gale
dreamy sinew
#

Sorry, bit too drunk to dig in to that right now

little gale
#

Might take the edge off you never know 😉

hallow fjord
#

Can someone spot why this template is not working? State is always "off" rather than "up" or "down".

  - platform: template
    sensors:
      sun_state:
        entity_id:
          - sun.sun
        friendly_name: "Sun State Test"
        value_template: >-
          {% if is_state('sun.sun', 'above_horizon') %}
            up
          {% else %}
            down
          {% endif %}```
#

I also have an icon_template with the same condition and that works just fine.

ivory delta
#

A binary sensor is only reporting as on/off? What a surprise.

#

You probably want a sensor.

hallow fjord
#

How did I miss that 😖 Thanks

sonic nimbus
#

Hello again 🙂 How to operate with two entities and two different service calls based on trigger?

#

here is the example what Im trying to do

#
    - service_template: >-
      {%- if trigger.event.data.switch == 'switch.bedroom_led_light_trafo' -%}
          switch.turn_on
          entity_id: trigger.event.data.switch
      {%- else -%}
          light.turn_on
          data_template:
            entity_id: >
              {{trigger.event.data.entity}}
      {%- endif -%}```
arctic sorrel
#

service_template for the service

#

You're trying to jam it all under the service template

sonic nimbus
#

maybe two actions to put?

arctic sorrel
#
    - service_template: >-
        {%- if trigger.event.data.switch == 'switch.bedroom_led_light_trafo' -%}
          switch.turn_on
        {%- else -%}
          light.turn_on
        {%- endif -%}
#

Then a data_template block with the entity_id section

#
      data_template:
        entity_id:
          {%- if trigger.event.data.switch == 'switch.bedroom_led_light_trafo' -%}
            {{ trigger.event.data.switch }}
          {%- else -%}
            {{ trigger.event.data.entity }}
          {%- endif -%}
sonic nimbus
#

tnx @arctic sorrel I get it now

#

just I have an error

#

I think I need to add > at entity_id?

#

in data_template section?

#

maybe you missed it?

arctic sorrel
#

Probably

#

I was just trying to quickly hack your thing

sonic nimbus
#

hehe ofc 🙂

arctic sorrel
#

It's worth taking the time to read through all the templating docs and examples

sonic nimbus
#

tnx

#

I am reading, but when it comes to logic, suddenly, I dont have an idea..

#

I was ready to write separate automations..but at the end, I think this is the right way..why not to use templates

arctic sorrel
#

Neither is right or wrong 😉

fast wedge
#

Hi, I'm not sure whether this is the right channel to ask, but didn't find anything better... I've upgraded from 0.111 to 0.112 and now all my template sensors/template switches/template lights are not working anymore 😦 Did I miss something in the breaking changes?

#

If it is not the right channel, can someone please point me to the right one?

buoyant pine
#

Any errors in the log?

fast wedge
#

none related to the templates. It might be abigger issue though: the time sensor is also stuck to the time I (re)start hass (using hass core/virutal env)

#

The first line in the log is a warning from the recorder "Ending an unfinished session". Could it be that the recorder is having a problem?

mighty ledge
#

That’s a whole lot of no-information

fast wedge
#

I tried disabling everything and enabling the whole sensors one by one and seems to work now. Only the recorder is still disabled.

#

So there might have been something wrong with my database for the conversion.

#

Seems that I managed to get it working again; sorry for the noise.

#

The strange thing is that I did not see any errors in the logs 😦

#

ok, I reenabled the recorder as well, and now everything seems to work again as it should. Very strange behaviour. But as long as everything works again, I am happy.

mighty ledge
#

Seems like you didn’t wait for the database to update

#

It’s in the release notes that a new database was deployed on .112 and existing databases needed to be converted. Which could take upwards of 3 hours depending on the size of your db

fast wedge
#

well, I updated yesterday at 23:00; I restart the server every day at 03:00, so it did have about 4 hours...

#

and later on I even deleted the whole DB and restarted HA (so , nothing to convert), but it didn't help either

#

So, if the biggest issue is that I lost the history, I can live with it; it will be regenerated in a couple of days 😄

#

Thanks!

#

(and sorry again)

arctic sorrel
#

If you have to restart daily you've got major issues with that host

valid musk
#

Can anyone help me work out how to cast the output value of a template to an array? I am trying to call service device_tracker.see and set gps In my data_template I have gps: "{{ trigger.json.gps }}" where gps in the trigger data is "gps": [51.509802, -0.086692] <- location data is dummy data

When the action runs it logs Error executing script. Invalid data for call_service at pos 1: None for dictionary value @ data['gps']

valid musk
shy badge
#

Hi Team, I have a power monitoring smart plug set up with tasmota to notify when the washing is finished. I have a binary sensor template created but how would I get this into Homekit so I can see the washing machine state?

#

nvm, think I got it 😛

shy badge
#

dam, almost had it. I have device_class: power but Homekit shows it as an occupancy sensor . . . . any ideas?

shy badge
#

Hmmm, friendly name and icon also not showing up.

velvet gate
#

no, cool username though.

inner mesa
#

I didn’t know that delay_on and delay_off existed, so that’s cool. I always use for: in automations triggers and conditions

keen flame
#

hey y'all. is there a button or an addon that lets you execute an API command in button press?

inner mesa
#

Depends how on what you mean by ‘API command’. You probably want call-service

#

And tap-action

winged dirge
#

Anyway to change unit_of_measurement so its set by template. i.e. I want to display ml, litres or kL depending on the flow rate of my water valve?

buoyant pine
#

Unfortunately not

winged dirge
#

any work around, I considered setting the unit to "" but this breaks stuff on my influxdb side

#

the problem is flow rate changes from tiny values to massive values

buoyant pine
#

Do you need to set a unit of measurement for it at all?

#

If so, apparently setting it to 1 is a workaround for when you want a unit of measurement (like if you want it to display a graph when looking at history)

winged dirge
#

I mean I'd prefer to all the rest of the values do, I don't have to but you know, I'd like to

#

hmmm maybe I could make multiple sensors and display those depending on flow rate

#

I wonder if lovelace can be dynamically updated based on a template

inner mesa
#

Or you can just display the value + whatever units you want in the UI if that’s what you want

#

Custom button card lets you use a template for the value

winged dirge
#

Yeah it would mess up influxdb as I pull stuff out based on units thou

inner mesa
#

Indeed

winged dirge
#

hmm.. not quite what I'm after, I kind of like the list of entities with Voltage, Flow Rate, kA and kW

#

I know its not feasible now at least

thorny snow
#

Hi, I've set up a template cover, which I want to use from lovelace. My config looks like this:

  • platform: template
    covers:
    templ_tertuer:
    friendly_name: "Rollade Terrassentür"
    position_template: '{{ states.cover.rollade_terrassentur.attributes.current_position | int }}'
    set_cover_position:
    service: cover.set_cover_position
    data:
    entity_id: cover.rollade_terrassentur
    position: "{{position}}"
    If I call the service "cover.set_cover_position" and position: 50 I get this error: Fehler beim Aufrufen des Service cover/set_cover_position. expected int for dictionary value @ data['position']
buoyant pine
#

need to use data_template instead of data

#

also in the future:

silent barnBOT
#

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

buoyant pine
#

or if it's approaching the line limit like yours is:

silent barnBOT
thorny snow
#

and this is correct "position: "{{position}}"" ?

#

thanks for the hint with pastebin...

buoyant pine
#

yeah that's fine, but again, you need to use data_template: instead of data:

thorny snow
#

yeah I've changed it and now it works... thanks @buoyant pine

queen meteor
glacial matrix
#

Good Evening, I am using the traccar plugin, and my device reports my bikes battery voltage, could someone tell me how I might be able to use a template to create a sensor please.

ivory delta
#

You'll have to start by sharing what format the data is in, otherwise we're just guessing 😉

glacial matrix
#
      thundercat_battery:
        friendly_name: Thundercat Battery
        unit_of_measurement: 'V'
        value_template: >-
            {%- if state_attr('device_tracker.thundercat', 'power') %}
                {{ state_attr('device_tracker.thundercat', 'power')|round }}
            {% else %}
                {{ states('device_tracker.thundercat') }}
            {%- endif %}
        device_class: battery

I think this works, but i'd like to round to two decimal places rather than a whole number, is that possible please. At the moment it seems a little overkill... 12.341000000000001

#

@ivory delta Sorry for not giving more info.

ivory delta
#

So use round(2)

glacial matrix
#

i wasn;t sure on how to format that. Thank you.

ivory delta
glacial matrix
#

Thank you. I'm just going to try and figure out how to get life360 battery charging information on a couple of phones as separate sensors.

glacial matrix
#
  - platform: template
    sensors:
      phone_battery_dad_charging:
       friendly_name: "Dad's Phone Battery Charging"
       value_template: >-
            {%- if state_attr('device_tracker.dad', 'battery_charging') %}
                {{ state_attr('device_tracker.dad', 'battery_charging') }}
            {% else %}
                {{ states('device_tracker.dad') }}
            {%- endif %}

not sure what i've done wrong, but if the device is charging it shows true, if it isnt it shows the location. do i just need to add

, 'battery_charging'

to the else argument?

wraith shell
#

hey guys I've got an idea in mind, not sure is viable so need some help

#

persistent notifications acumulate while I'm away from home. When I come back I'd like alexa to spell them, either is there only one on if here are 4 or more notifications

#

is that possible?

#

I can't find a template to retrieve the message or title of the current notifications

#

either if there is only one*

#

@glacial matrix is_state_attr instead maybe?

#

instead of state_attr

thorny snow
#

I need a template expert :-)
I currently counting if there is an attribute in an Json Response with:

      {% for id in value_json if id.status != "delivered" -%}
      {%- if loop.last -%}
      {{ loop.length }}
      {%- endif -%}
      {%- endfor -%}

Unfortunatelly there is also the case the there is no response. So there is no loop count.
In case there is no resonse I need to return a 0:
Any Idea how to achieve this?

dreamy sinew
#

Would need to know what the payload looks like

thorny snow
#

The goal is to count the items where the status are not delivered

glacial matrix
#

Morning guys and gals, I'm trying to create a sensor to see if a phone is charging. I'm monitoring that with life 360. I've made a template, but it just shows as unknown now. My previous attempt wasn't working either:

  - platform: template
    sensors:
      phone_battery_dad_charging:
       friendly_name: "Dad's Phone Battery Charging"
       value_template: >-
            {%- if state_attr('device_tracker.dad', 'battery_charging') %}
                {{ state_attr('device_tracker.dad', 'battery_charging') }}
            {% else %}
                {{ is_state_attr('device_tracker.dad', 'battery_charging') }}
            {%- endif %}

many thanks.

silent barnBOT
arctic sorrel
#

Other than testing, your indenting is somewhat all over the place

silent barnBOT
#

YAML is the mark up language used by Home Assistant, consistent indenting (two spaces per level) is key. Here is a primer, and this explains multi-line templates. For validating YAML see YAML Lint.

glacial matrix
#

I didnt know i could test a template, thank you. I think i might have cracked it, i don't an if else statement in there so i think this might be correct:

  - platform: template
    sensors:
      phone_battery_dad_charging:
       friendly_name: "Dad's Phone Battery Charging"
       value_template: {{ state_attr('device_tracker.dad', 'battery_charging') }}
#

nope. something wrong with the syntax i think.

arctic sorrel
#

You're not trying to create a binary_sensor there are you?

glacial matrix
#

ohhh, it might be, it will just be reporting true or false based on if the device is charging or not. It is showing true or false in the testing editor, but when i run the config check i get:

 Error loading /config/configuration.yaml: while parsing a flow mapping
  in "/config/sensors.yaml", line 405, column 25
expected ',' or '}', but got '<scalar>'
  in "/config/sensors.yaml", line 405, column 80
arctic sorrel
#

That's down to the lack of quotes 😉

#
       value_template: "{{ state_attr('device_tracker.dad', 'battery_charging') }}"
glacial matrix
#

Perfect thank you!

ancient karma
#

I get this error 2020-07-07 10:29:41 WARNING (MainThread) [homeassistant.components.mqtt.light.schema_template] Invalid brightness value received

#

when i do brightness_template: '{{ value_json.brightness * 2.55 }}'

#

when I try to multiply that is..

#

but if I use brightness_template: '{{ value_json.brightness }}' there is no error

#

why so?

#

i have tried brightness_template: '{{ value_json.brightness | float * 2.55 }}'

#

still same error

#

any ideaS?

arctic sorrel
#
brightness_template: '{{ (value_json.brightness * 2.55)|round(0) }}'
ancient karma
#
brightness_template: '{{ (value_json.brightness * 2.55)|round(0) }}'

thanks!

#

i must have spent more than an hour at this 😦

arctic sorrel
#

Integer between 0 and 255 for how bright the light should be

#

Integers are whole numbers

ancient karma
#

yes.... too used to auto typecasting various other scripting languages

left patio
#

hi, can someone tell me why my sensor isnt displaying in the webui?

sensor:

  • platform: file
    name: teststatus
    file_path: "/tmp/test.txt"
#

added this to my configuration.yml and text.txt contains the string True

silent barnBOT
#

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

buoyant pine
#

also did you whitelist the /tmp dir (and is that the correct path)?

left patio
#

path is correct but i didnt do any whitelisting

buoyant pine
#

keep in mind if tmp is in your config dir, then /tmp is not the correct path

left patio
#

hm added it to my config.yml but now ha tells me something is wrong:

The following integrations and platforms could not be set up:
whitelist_external_dirs

buoyant pine
#

needs to be nested under homeassistant: in your config

left patio
#

ok that fixed this but i sill cant find the sensor

#

should a file sensor be visible?

buoyant pine
#

should be sensor.teststatus

#

check the log for errors

left patio
#

ok thx for helping me!

green wasp
#

so my ecobee thermostat has an attribute named 'equipment running' and is a comma separated list (there is more than one running at the time). What do you think is the best way to keep track of this? I eventually want to be able to graph and calculate how long each one is on

#

This way i can see how long the compressor and/or fan has been running

#

binary sensor template?

buoyant pine
#

yeah, you could make a template binary sensor for each piece of equipment with this as the value template:

"{{ 'fan' in state_attr('climate.thermostat', 'equipment_running') }}"
``` naturally, adjust as needed for your specific setup
#

and then use each of those template binary sensors in history stats sensors (or whatever you want to use to track their history)

#

@green wasp ☝️

green wasp
#

@buoyant pine is there anyway to make such templates more dynamic or do you really have to manually create a sensor for each possible value?

#

its really only two in this case, but more wanting to know for other use cases

buoyant pine
#

not really

green wasp
#

ok, no problem. wasnt sure you could loop through values and have it create the sensors. makes sense though

buoyant pine
#

i mean, you can use a for loop at developer tools > template to generate the code for multiple template sensors (or whatever) to copy and paste in the config file

#

i've done that before for some things

green wasp
#

i did that, but doesnt that go into a value template for a single sensor? i mean, how could it dynamically create different sensors based on that

buoyant pine
#

i'm saying if you want to generate several template sensors that all use the same code except for the entity (or whatever), you can generate the code for those several sensors that way

#

to then copy and paste in your config file

#

not really a standard use but can be helpful

inner mesa
#

write code to write code 👍

buoyant pine
#

basically lol

inner mesa
#

you'll engineer yourself right out of a job, son

green wasp
#

ha, no, i meant for maybe situations where you dont know what the different values could be in that comma separated list

#
        friendly_name: "HVAC Compressor"
        value_template: >-
          "{{ 'compCool1' in state_attr('climate.thermostat', 'equipment_running') }}"```
#

hmm, when i check the value_template code in the developers tool, its coming up as true, but looking at states, its listed as off

#

shouldnt true be 'on'?

buoyant pine
#

ditch the outside quotes

#

you don't use outside quotes when making it a multi-line template with >

green wasp
#

ah man,i should have known that

#

thanks

buoyant pine
#

or just do this:

value_template: "{{ 'compCool1' in state_attr('climate.thermostat', 'equipment_running') }}"
green wasp
#

yep. thanks

fallen sorrel
#

trying to extend functionality and create power saving mode by only turning on half of lights when motion initially activated,.. but if motion continues,.. then turn all lights on... and of course using a variable timeout delay depending on the time of day... Have tried several approaches but got stumped trying to create yaml logic flow,.. have drafted 'mickey mouse' version in C'ish,. but not able to see a way forward to create within yaml code,.. does anyone have any suggestions.. Many tx https://pastebin.ubuntu.com/p/PzM8hzR99M/

ivory delta
#

Looks like you're overcomplicating things. Just make two automations, one for initial motion, one for prolonged motion. If you're good with automations, it can even be written as one. But... you're in the wrong place for that. #automations-archived

fallen sorrel
#

yes,.. you could be right,.. I will think some more,.. and pay the #automations-archived folks a visit maybe later...

stone lintel
#

This might be the wrong channel but is there a way of using a template to change the status of an input Boolean so rather than the template saying the status of the input Boolean is on, it says the status is home or away for example?

buoyant pine
#

sure.

value_template: "{{ 'Home' if is_state('input_boolean.whatever', 'on') else 'Away' }}"
stone lintel
#

Amazing thanks!

buoyant pine
#

note that it doesn't change the state of the boolean, just the template sensor

stone lintel
#

That’s fine!

#

Thanks for the help

stone lintel
#

I've just tried this and it's still showing as on rather than home?

   sensors:
      amy_status:
        friendly_name: "Amy Home"
        value_template: "{{ 'Home' if is_state('input_boolean.amy_home', 'on') else 'Away' }}"

is what I've set up and when I try this template
Amy is {{ states("input_boolean.amy_home") }}.
The response is on or off rather than Home or Away?
Sorry if I am missing something silly....

dreamy sinew
#

sounds like your sensor is a binary sensor which can only ever be on or off

stone lintel
#

Ah okay, thanks, will need to do something else with that then!

dreamy sinew
#

could do Amy is {{ 'Home' if is_state('input_boolean.amy_home', 'on') else 'Away' }}

#

or make that sensor not a binary_sensor

stone lintel
#

Ah that's perfect thanks! I probably misread the help above!

buoyant pine
#

Template sensors create new sensors with a state based on the template you provide. The original entity is unaffected (that's what I meant by it doesn't change the state of the boolean)

stone lintel
#

Understood thank you!

quaint saffron
#

something something i have a sensor, i need to to read out 3 different templates for 3 different parts of the rgb value of a light, it currently returns a string, how do i make it not?

austere relic
#

so if I got it right this should work:

#

rgb_color: [{{ states.light.light1.attributes.rgb_color.1 }},{{ states.light.light1.attributes.rgb_color.2 }},{{ states.light.light1.attributes.rgb_color.3}}]

#

ops, now

#

maybe @arctic sorrel can correct me one more time 😄

silent barnBOT
arctic sorrel
#

Test there, the theory is ... reasonable

austere relic
#

i did test it there, it was more about the function of the array now

arctic sorrel
#

If that provides the right output then yes

quaint saffron
#

is that for the sensor or the automation?

arctic sorrel
#

As it's three values

quaint saffron
#

what?

inner mesa
#

seems like state_attr() would be a bit better

quaint saffron
#

that doesnt even look like the code of the sensor

austere relic
#

@quaint saffron for the automation that does not require a sensor anymore

quaint saffron
#

so i switched to the templates channel so i can get info on automations now?

#

not even gonna question it

#

now i have a configuration error

#

i didnt even edit the configuration file

ivory delta
#

'I have an error' is pretty useless if you're after help. Post the error and the config.

quaint saffron
#

i dont even know what the error is

#

it opened a window and im currently reading through it

#

it seems to just be the values of every single sensor connected to home assistant together with a template that i 100% have never seen before and does not belong to me

inner mesa
#

only the first bit of the output from a config check is typically useful

#

a single error causes the rest of the file to look like crap

quaint saffron
inner mesa
#

that's just the default text

#

examples

quaint saffron
#

ok?

#

and where is the error?

inner mesa
#

what's your quesiton?

quaint saffron
#

i dont know

inner mesa
#

You said:

#

now i have a configuration error
i didnt even edit the configuration file

quaint saffron
#

what do you mean "whats your question?"

ivory delta
#

No error 🤷‍♂️

inner mesa
#

and then you showed a screenshot of the default dev tools -> Templates screen

quaint saffron
#

i changed the automation like i was told to do, then it told me i had a configuration error, and then it redirected me there

#

thats all i know

#

yes, i am also confused

inner mesa
#

we have yet to see your error

quaint saffron
#

so do i

#

it sure would be helpful if home assistant decided to show me the error

ivory delta
#

It redirected you to devtools > Templates? Odd, that's never happened before.

quaint saffron
#

but clicking on the "see the logs" button in the notification redirects me to /developer-tools/logs, which is appearently not a valid location

#

the first time it then redirected me to templates, right now its just showing a blank screen

ivory delta
#

Go to Configuration > Logs

inner mesa
#

ah, that just changed and it's possible that the link wasn't updated

quaint saffron
#

"Error loading /config/configuration.yaml: invalid key: "OrderedDict([('states.light.fakepixel1.attributes.rgb_color.1', None)])" in "/config/automations.yaml", line 63, column 0"

#

so the error isnt in configuration, its in the automation

#

its

arctic sorrel
#

All YAML is in the configuration, ultimately

quaint saffron
#

i dont like working with home assistant, it can be a bit weird sometimes

#

ok so the new code doesnt work

#

now what?

arctic sorrel
#

~share the relevant section

silent barnBOT
ivory delta
#

Square braces around a template? raised_eye

#

No wonder it's complaining about an OrderedDict.

quaint saffron
#

that was literaly the only suggestion of a fix

ivory delta
#

An OrderedDict is like an array in any other language. It wants a string, I think....

quaint saffron
#

that is the relevant section he wants

ivory delta
#

Man, the attitude is strong with this one.

#

People here are trying to help you, don't piss them off.

quaint saffron
#

?

#

he asked for the relevant section

#

thats the relevant section

arctic sorrel
#

It's useful to get the actual section of the automation

quaint saffron
#

i did the thing i was told to do

#
action:
  - data_template:
      brightness: '{{ states.sensor.brightness_fakepixel1.state }}'
      rgb_color: [{{ states.light.fakepixel1.attributes.rgb_color.1 }},{{ states.light.fakepixel1.attributes.rgb_color.2 }},{{ states.light.fakepixel1.attributes.rgb_color.3}}]
      entity_id: light.table_light
    service: light.turn_on```
silent barnBOT
#

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

ivory delta
#

Rule 1 and rule 2 😉

#

D'oh... it's rule 3 this time.

arctic sorrel
#

Possibly you need to |int everything

quaint saffron
#

neither of those things tell me anything

arctic sorrel
#

As mentioned earlier, template output is a string - text

#

Most of the above needs an integer - number

#
{{ states.sensor.brightness_fakepixel1.state|int }}
``` for instance
quaint saffron
#

the brightness works tho

#

"Error loading /config/configuration.yaml: invalid key: "OrderedDict([('states.light.fakepixel1.attributes.rgb_color.1|int', None)])""

fierce hornet
#

How can I make a sensor entity (using templates I guessed) that grabs a part of a state from another entity?

arctic sorrel
quaint saffron
#

i did the thing, it still doesnt work

#

@ivory delta i still dont know what youre talking about with rule 3

ivory delta
#

Never mind 🙂

quaint saffron
#

ok

#

any other suggestion on how to fix the issue?

ivory delta
#

Me? No. Be patient and wait for someone to answer.

quaint saffron
#

thats...

#

what im doing

quaint saffron
#

sending google links os completely worthless as i 100% get different results than you do

#

main difference being that a lot of my results are in german

ivory delta
#

Did you even try the link?

inner mesa
#

I searched for "rgb_color template home assistant"

quaint saffron
#

i know

#

you posted a link of it

ivory delta
#

100% different to his top result...

quaint saffron
#

this was my first result

#

so uhm

#

different result because different country and search history

inner mesa
#

fair enough, point was that it's findable with a simple Google search

#

and "ya gotta be willing to do some research"

ivory delta
#

Different result. Still has your answer.

#

I'm not really seeing the problem - RobC suggested a valid search which resulted in getting the right answer.

quaint saffron
#

mate, i have absolutely no idea what the problem even is

#

someone suggested a fix, said fix throws up an error, i was waiting for a response from them on how to fix their fix

inner mesa
#

do you really want an answer?

ivory delta
#

With an attitude like yours, I'm not surprised you were left waiting.

#

It needs to be a list of ints. There's how to do your list of ints.

quaint saffron
#

i want an answer, i dont want continual sass on "oh this is so eaaaassyy just google this thing where 90% of the terms used you dont even recognise as being valid words"

ivory delta
#

The irony.

inner mesa
#

<plonk>

quaint saffron
#
                          Error loading /config/configuration.yaml: while parsing a block mapping
  in "/config/automations.yaml", line 62, column 7
expected <block end>, but found '<block mapping start>'
  in "/config/automations.yaml", line 63, column 10```
arctic sorrel
#

Formatting problem

quaint saffron
#

i dont even know what that meeeaaaans

arctic sorrel
#

It means you messed up indenting or quotes

quaint saffron
#
  - data_template:
      brightness: '{{ states.sensor.brightness_fakepixel1.state }}'
          rgb_color:
          - '{{ (what_color[0],what_color[1])|join|int(0,16) }}'
          - '{{ (what_color[2],what_color[3])|join|int(0,16) }}'
          - '{{ (what_color[4],what_color[5])|join|int(0,16) }}'
      entity_id: light.table_light
    service: light.turn_on```
ivory delta
#

Yup

#
  action:
  - data_template:
      brightness: '{{ states.sensor.brightness_fakepixel1.state }}'
      rgb_color:
        - '{{ (what_color[0],what_color[1])|join|int(0,16) }}'
        - '{{ (what_color[2],what_color[3])|join|int(0,16) }}'
        - '{{ (what_color[4],what_color[5])|join|int(0,16) }}'
      entity_id: light.table_light
    service: light.turn_on```
#

You can't just indent things at random. You indent things that belong to something slightly less indented.

silent barnBOT
#

YAML is the mark up language used by Home Assistant, consistent indenting (two spaces per level) is key. Here is a primer, and this explains multi-line templates. For validating YAML see YAML Lint.

ivory delta
#

And I probably still messed it up but it's an improvement 😄

arctic sorrel
#

If you're going to stick with HA it's really important (hell, critical) you understand YAML

rugged laurel
#

or JSON

quaint saffron
#

i didnt indent that, i just pasted the code i was given

ivory delta
#

You pasted it with incorrect indentation. Don't blame the pasting.

#

You still need to proof read things.

arctic sorrel
#

I don't often use the 🤢 emoji... but when I do 😉

ivory delta
#

I don't hate it...

#

Is this the whole 'JSON is valid YAML' in action?

quaint saffron
#

Remote 1: Error executing script. Unexpected error for call_service at pos 1: Error rendering data template: UndefinedError: 'rgb_fakepixel1' is undefined

#

i would really like it if home assistant could stop deselecting all the text i have selected the moment i get 2 pixel too far from the line im trying to select

arctic sorrel
#

That'll be your browser...

#

Or fingers

ivory delta
#

TIL that HA is to blame for everything.

quaint saffron
#

it does it on both chrome and firefox

ivory delta
#

Two different browsers? Must be the fingers then.

quaint saffron
#

and its the only thing ive ever seen anywhere that does it

#

most things dont care if you go outside the line a little, because thats just what happens when you move a mouse

#

wrists arent made to move a perfectly straight line

#

hell, notepad plus doesnt even care if i leave the window

rugged laurel
#

Home Assistant does not do that in any of it's editors

quaint saffron
#

im pretty sure i could connect a second screen and move my mouse there and it wouldnt loose my selection

ivory delta
#

Can we get back on topic? What's your issue?

rugged laurel
#

I left the window to write this, and it's still selected

quaint saffron
#

it does when youre trying to select text in the logs

#

i mean you move your mouse while still holding left click to select it

ivory delta
quaint saffron
#
      brightness: '{{ states.sensor.brightness_fakepixel1.state }}'
      rgb_color:
          - '{{ (rgb_fakepixel1[0],rgb_fakepixel1[1])|join|int(0,16) }}'
          - '{{ (rgb_fakepixel1[2],rgb_fakepixel1[3])|join|int(0,16) }}'
          - '{{ (rgb_fakepixel1[4],rgb_fakepixel1[5])|join|int(0,16) }}'
      entity_id: light.table_light
    service: light.turn_on```
#

i know why this doesnt work

inner mesa
quaint saffron
#

rgb_fakepixel1 isnt a valid value because fakepixel1 is supposed to be a sensor

arctic sorrel
#

I'm surprised that ever worked when you tested it

quaint saffron
#

it doesnt

#

thats the thing

arctic sorrel
quaint saffron
#

thats why im here

arctic sorrel
#

Well, where do you think the data is?

quaint saffron
#

so, how do i change that code to work with the sensor?

#

i dont know

#

somewhere in the ram

arctic sorrel
#

I'm done...

quaint saffron
#

i dont understand the question

#

where would the data be?

ivory delta
#

No-one can tell you where the data is. You're the one providing it.

#

Our crystal balls clearly aren't working today.

silent barnBOT
#
:8ball: 8Ball prdiction:

Question: ~8ball when will the crystal ball work
Answer: As If

quaint saffron
#
      rgb_fakepixel1:
        friendly_name: "RGB Fake Pixel 1"
        value_template: '{{ states.light.fake_neopixel_1.attributes.rgb_color }}'```
inner mesa
#

the sound...of good choices

ivory delta
#

And what does {{ states.light.fake_neopixel_1.attributes.rgb_color }} give you in devtools > Templates?

quaint saffron
#

i have never been asked the question "where is the data"

#

gonna be honest, that one threw me a teeny tiny bit

ivory delta
#

I'm very close too, Rob

quaint saffron
#

the rgb fake pixel 1 is (71, 71, 255),

#

its 3 integers in a string, as we discussed earlier

#

or a template

#

or whatever we are calling this

#

does that count as a matrix?

#

and im sorry that i dont know what "where is the data" is supposed to mean

ivory delta
#

Well I wouldn't expect that to be a string. Your template was outputting a string.

quaint saffron
#

ok?

#

was it?

#

so is that a string or not?

ivory delta
#

It's a tuple. Google it.

#

I'd Google for you but mine's in a different language.

quaint saffron
#

well i was told my sensor was outputting a string

#

how do i work with a tuple then?

ivory delta
#

Your sensor was. That tuple isn't a string, your incorrect template transformed it into a string.

#

You Google it.

quaint saffron
#

how is my template incorrect?

ivory delta
#

Man. The volunteers in here give up a lot of their time to help people out. They help with all kinds of questions and have a ton of patience for newbies. But this is the first time I've seen so many people give up on someone.

#

And I take no pleasure in admitting that I've run out of patience too. Good luck.

quaint saffron
#

as someone who also voluntarily helps out on a different server, i completely understand the frustration of dealing with someone like me

arctic sorrel
#

You were handed a link to a complete working solution, that you butchered randomly 🤷

quaint saffron
#

i also understand myself here, because as a volunteer i wouldnt act this way

arctic sorrel
#

You also clearly need to read the templating docs

quaint saffron
#

you said that the code would never work

arctic sorrel
#

That'd be over an hour and a very different solution ago

quaint saffron
#

i "butchered" that code under the assumption that it could be made to work

arctic sorrel
#

That abomination would never work

#

It can be

#

If you read the templating docs

#

And learn how templates work

quaint saffron
#

i made the change to the what_colour code so that the name would work with my sensor, which i assumed to be outputting a string

#

then i realized that it probably wont work because it needs to first get the data from the sensor

arctic sorrel
#

See the forum post you were linked to

quaint saffron
#

so i asked about that, and them im informed that my sensor outputs a TUPLE

arctic sorrel
#

Probably also ditch the intermediate sensor

#

Until it works in the Templates test screen, it won't work in an automation

quaint saffron
#

the problem is that i cant see where the guy got his "what_colour" string from

inner mesa
#

BTW, just a plug for pnbruckner's contributions on the forum. He's patient, provides complete solutions, and reads the core code to figure out how something works, whether it should work, or why it doesn't

#

believe that guy when he says something

quaint saffron
#

thats also kind of my problem

#

i keep getting bits of solutions

#

and then i need to change something else

#

and it keeps getting more complicated until i arrive at a point where i have no idea why i have some piece of code

#

so i dont need the sensor anymore?

arctic sorrel
#

That, bluntly, suggests you're not taking the time to stop and learn the platform...

quaint saffron
#

i can definitely for sure delete that?

hollow bramble
#

A case of the sighted leading the blind, and the blind continually wandering in the wrong direction

quaint saffron
#

i dont need to learn the platform, i need this one thing to work

#

no its a case of the sighted telling the blind to "turn right" and then only telling them to turn left again once they ran into the wall and posted a log file

#

i just need 1 piece of code that will make one lamp take the colour and brightness values from another lamp

#

i dont need an instruction on how to apply a string to a lamp unless i also get an instruction on where to get the string from

ivory delta
#

Today you need one piece of code. Then you'll be back in the future asking more stupid questions because you didn't learn anything this time.

quaint saffron
#

i dont wanna have to spend 15 years reading through the absolutely massive list of things you can do in home assistant

ivory delta
#

'Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime.'

#

The experts here didn't spend 15 years.

arctic sorrel
#

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.

quaint saffron
#

teach a man to fish and he will be occupied for 8 hours trying to catch a fish, give a man a fish and hell just have his fish in 5 seconds

arctic sorrel
#

Bluntly, if you don't want to learn how HA works, HA isn't a good choice for you. Go pick something more pointy-clicky.

quaint saffron
#

im not gonna actively avoid trying to learn things

#

but i need to know how to do the thing

ivory delta
#

But you are...

#

You're avoiding learning. You said yourself you just want to be given the answer.

quaint saffron
#

then in the future ill know "oh, last time i did this thing"

rugged laurel
#

@quaint saffron Go and read through the " Before You Ask:" section of #rules

silent barnBOT
hollow bramble
#

Honestly all the time spent complaining could have been spent reading the docs and you'd be able to solve your own problem by now

quaint saffron
#

i just need to know where to get the string from the light

arctic sorrel
#

And, that's been answered, more times than I can count

quaint saffron
#

where?

quaint saffron
#

you said i should look at the forum post i was linked, i said i dont see where he gets his string from

#

and thats the last time we actually talked about the string

hollow bramble
quaint saffron
#

usually when someone asks me "hey, i made this thing on an arduino, why doesnt my code work" i go "heres your mistake, heres the fixed version, heres how to avoid it in the future", not "read the refrence section and LEARN"

#

those two

#

the data it gives me is a tuple

#

as we have established

#

the tuple is appearently useless

#

because i need a string

rugged laurel
#

@quaint saffron Go and read through the " Before You Ask:" section of #rules last warning!

carmine aspen
#

Hi all, maybe an extra set of eyes can help me. In HA, i get values for the two attributes, but the statement always go to the 'else' https://pastebin.com/7K6v7XYg

#

Am I going about getting the values of the attribute the wrong way?

hollow bramble
#

What is the output of the template in the templates dev tool?

carmine aspen
#

I can't get one

ivory delta
#

if (state_attr('device_tracker.cgs9p', 'rssi') | int) > (state_attr('device_tracker.rha_cgs9p', 'rssi') | int)? You're checking that x is greater than x?

#

That'll always be false.

arctic sorrel
#

You could test with:

{{ state_attr('device_tracker.cgs9p', 'rssi') | int }}
{{ state_attr('device_tracker.rha_cgs9p', 'rssi') | int }}
ivory delta
#

Oh, different entities... my bad.

carmine aspen
#

yea they look similar but different

#

@arctic sorrel that returns nothing in the editor

#

it's just blank

rugged laurel
#

Then the entity_id's are wrong

arctic sorrel
#

Are you on 0.112.0?

quaint saffron
#

@rugged laurel i did all of those things before i asked my question, then i got given part of a solution, then i asked "how do i finish making this solution", and now i need to troubleshoot the solution

carmine aspen
#

ya 112.0

arctic sorrel
#

Upgrade 😉

quaint saffron
#

and appearently ive already been given the solution for the solution

arctic sorrel
#

The top four lines are truncated

quaint saffron
#

but i dont know where

hollow bramble
#

even if the entity_ids are wrong it should produce two zeroes

carmine aspen
#

lemme upgrade

hollow bramble
#

Oh is there a template bug in 112?

ivory delta
#

The first few lines didn't render correctly.

rugged laurel
#

UI bug, the top 65px are hidden

hollow bramble
#

huh. interesting

quaint saffron
#

and people are telling me that they told me the solution to the solution, and then i ask where it was, i get told read the "before you ask" section

#

technically, my question is "where did you tell me where to find that?", and im not getting much on the forums for that one, tbh

ivory delta
#

I believe you're being pointed to that section (by a mod, no less) partly for this:

When you ask your question, display the fact that you have done these things first; this will help establish that you're not being a lazy sponge and wasting people's time. Better yet, display what you have learned from doing these things. We like answering questions for people who have demonstrated they can learn from the answers.

carmine aspen
#

aha! now i get two 0's. at least something is showing now lol

#

i must be typing the attribute or entity id wrong

ivory delta
#

Zeroes are good. It means your template is valid and finding something.

carmine aspen
#

lemme double check

quaint saffron
#

i have learned nothing from doing these things because appearently the things i was looking for are unrelated to my issue

ivory delta
#

If you wanted to learn to build a car, you're probably not going to find a single post that answers all your questions. You have to break down the problem into smaller parts and solve each one.

#

Do that. Figure out what you don't know and find those answers.

#

Build upon your knowledge piece by piece.

quaint saffron
#

because appearently im getting a tuple, not a string, and i cannot figure out how to get a string

carmine aspen
#

okay i figured it out! the string attribute output is '-16,'

#

the comma is throwing it off

quaint saffron
#

i have never told someone "just build your knowledge"

carmine aspen
#

when it trys to convert to int

quaint saffron
#

i usually tell them how to solve their problem

carmine aspen
#

now to find out how to filter out the comma

rugged laurel
#

use replace or [:-1] at the end

quaint saffron
#

this is the equivalent of asking my teacher "whats 15 + 9?" and my teacher going "come on, you know 15 + 9, you can figure this out. i believe in you, champ"

ivory delta
#

Pretty terrible analogy, if we're honest. If you're been taught addition, you should be able to add any two numbers.

rugged laurel
#

no... this is the equivalent of banging to rocks together

ivory delta
#

We're trying to teach you 'addition' here, so you can solve your own problems next time.

quaint saffron
#

just tell me how to get a string

ivory delta
#

The incessant complaining isn't doing you any favours.

quaint saffron
#

dont tell me "go look up how to get a string"

#

i cant figure out how to get a string

ivory delta
#

You're far less likely to get help from anyone if you do nothing but piss them off.

quaint saffron
#

im past the point of looking it up

ivory delta
#

And people are past the point of caring.

quaint saffron
#

i just need to know "this is how you get a string, next time you want a string, this is how you get it"

carmine aspen
#

@rugged laurel sorry not familiar with that, {{ state_attr('device_tracker.cgs9p', 'rssi') [:-1] }} produces blank

#

just quotes

ivory delta
#

No space before the [

#

The [] bit is operating on the result of the preceding function.

quaint saffron
#

ill admit, the analogy doesnt wokr

hollow bramble
#

@quaint saffron please stop complaining. It's getting very old. Put in the tiniest amount of effort. You are obviously not the first person to match light rgb values in a template.

ivory delta
#

It's just defining the start and end of an 'array' of characters from the original string.

quaint saffron
#

its me, asking my teacher "HOW do i add these together" and my teacher going "you can just figure it out"

ivory delta
#

In this case, you don't care about the start (which would have been before the colon), only the end.

carmine aspen
#

gotcha. I understand, but still blank when deleting the space

#

playing around with it now

quaint saffron
#

appearently the only person who has done it uses code that physically cannot possibly work

hollow bramble
#

What person?

ivory delta
#

It works for others.

#

If it doesn't work for you, you're doing something wrong somewhere.

quaint saffron
#

also i figured out how the guy got the "what_color" string, he provides it to the function when he calls it

#

which doesnt work for me because i need it to get the string from the light value of the other light

#

this is the other guy that tried to have 2 lights match

ivory delta
#

Build upon your knowledge piece by piece.

quaint saffron
#

thats the only thing i can find

#

and it only works for brightness, and i dont know how it worked for the second guy there that asked how to do it for rgb

#

because appearently it shouldnt work

hollow bramble
#

I have no way to test this because I don’t have any lights that can change color
You mean this guy?

quaint saffron
#

the other guy who thanked him and then appearently no longer had any issues

#

im counting that as "probably worked for him"

hollow bramble
#

That's a major assumption

quaint saffron
#

though there is a chance that it 0 people have done this before

carmine aspen
#

okay, i ended up using split because there was parenthesis at the beggining and end i needed to filter out

hollow bramble
#

Yes. There is also a chance that the sun is made of cotton candy

quaint saffron
#

if youre thinking that his success is too big an assumption, ill gladly go with "literally no one has managed this before me"

carmine aspen
#

it should work now. thanks for the tip about upgrading. I never would have realized that

quaint saffron
#

because that was the only one i found

ivory delta
#

if youre thinking that his success is too big an assumption, ill gladly go with "literally no one has managed this before me"
You're definitely not that special.

quaint saffron
#

ok

#

cool

#

then just get me like a forum post from a guy who did manage have 2 lights match each other, cause i cant

#

i got one guy who applied a string to a light, but i dont know how to get a string FROM a light

ivory delta
#

Wow. We're on to demands now?

quaint saffron
#

you can take it like that if you want to

hollow bramble
#

Haven't we been there?

ivory delta
#

I'm surprised the hammer hasn't come down already.

hollow bramble
#

You can lead a horse to water, you can put its face in the water, but the horse can still choose to drown before it drinks

#

Now you have the template (from your sensor). You have the means of pulling out values from a tuple. The rest is up to you.

ivory delta
#

And yet, I feel this saga hasn't ended.

quaint saffron
#

thanks, thats exactly what i needed, now i know how to get values from a tuple, now i can do it again in the future, my knowledge has expanded

hexed galleon
#

Easiest way to achieve switch/case with if/elif?

inner mesa
#

that's kinda open-ended

#

there's the way:

#
          {% if trigger.entity_id == "binary_sensor.garage_water_heater_leak_heartbeat" %}
            "Water Heater heartbeat missed!"
          {% elif trigger.entity_id == "binary_sensor.uph_humidifier_leak_heartbeat" %}
            "Upstairs Humidifier heartbeat missed!"
          {% elif trigger.entity_id == "binary_sensor.kit_refrigerator_leak_heartbeat" %}
            "Refrigerator heartbeat missed!"
          {% elif trigger.entity_id == "binary_sensor.mbath_vanity_leak_heartbeat" %}
            "Master Bathroom Vanity heartbeat missed!"
          {% else %}
            "Espresso Machine heartbeat missed!"
          {% endif %}
#

but there are other ways to skin that cat

hexed galleon
#

Yep, seems to be the way. Sorted 🙂

dreamy sinew
#

I like the dictionary method

inner mesa
#

Mine is the "I came from some other language and am looking for something that looks like it" method

#

lowest-common-denominator programming 🙂

dreamy sinew
#
{% set map = {
"entity_1": "thing", "entity_2": "other thing"
} %}
{{ map.get(trigger.entity_id, "default") }}
#

It's a tad cleaner and a lot shorter my way

hexed galleon
#

That IS cleaner! Didn't realise there was a get function. What about scope of the variable setting? Would I need to set the same map for both a value_template and a icon_template? Or does it persist the variable for the entity?

dreamy sinew
#

You would need to double it

#

The scope is just the specific _template: block

hexed galleon
#

Figured that's likely the case. May even be safer for me to just use an input_text which is modified through AppDaemon based on state changes. That way I can maintain the map in a single location.

#

Though to be fair, likely overkill for "who unlocked the door" 😛

dreamy sinew
#

Lol

opal dawn
#

Hi all may I ask a question about tempalting. Question is make a very long template line readable for example to continu on a next line / row

silent barnBOT
#

Don't ask to ask, just ask your question. Then people can answer when they're around.

When you do ask a question, try to provide as much background detail as possible. Ask yourself these questions first so that others don't have to:

  1. What version of the Home Assistant are you running? (remember, last isn't a version)
  2. What exactly are you trying to do that won't work?
  3. Is the problem uniform or erratic?
  4. What's the exact error message?
  5. When did it arise?
  6. What exactly don't you "get"?
  7. Can you share sample code, ideally with line errors where the error occurs?
opal dawn
#

value_template: "{{ states('sensor.time') == (state_attr('input_datetime.spray_moment_morning', 'timestamp') | int | timestamp_custom('%H:%M', False)) or (states('sensor.time') == state_attr('input_datetime.spray_moment_afternoon', 'timestamp') | int | timestamp_custom('%H:%M', False)) or states('sensor.time') == (state_attr('input_datetime.spray_moment_evening', 'timestamp') | int | timestamp_custom('%H:%M', False)) }}"

#

I have this as one complete long line.....

silent barnBOT
arctic sorrel
#

It's likely going to be easier to spread over multiple lines, in a multi-line template, and test all the steps

#
value_template: >-
  {{ states('sensor.time') == (state_attr('input_datetime.spray_moment_morning', 'timestamp') | int | timestamp_custom('%H:%M', False))
    or
  (states('sensor.time') == state_attr('input_datetime.spray_moment_afternoon', 'timestamp') | int | timestamp_custom('%H:%M', False)) 
    or 
  states('sensor.time') == (state_attr('input_datetime.spray_moment_evening', 'timestamp') | int | timestamp_custom('%H:%M', False)) }}
hollow bramble
#

A for loop would probably be the way I would go about it

arctic sorrel
#

Splitting it over multiple lines also highlights a possible bracket issue 😉

opal dawn
#

I tried a few ways. And it looks OK when I tried in the templating service in Hassio. But when compiling it / restarting HASSIO most of the ways give error

hollow bramble
#

what error?

opal dawn
#

Oef... Deleted those errors

#

I will give the above one ago (Y)

thorny snow
#

Hey - probably a noob question here, but I've tried to create a new template for a sonoff sensor, as the temperature value needs dividing by 100 to render correctly. I've spent hours looking around for why it's not working, and I have no idea. Is there a good guide that anyone can point me to that highlights how you get custom templates to render correctly for an entity? I'm using this integration https://github.com/AlexxIT/SonoffLAN/tree/v2.0.0#sonoff-th-and-pow and guide to implement the template but not having much luck

opal dawn
#

Ugh @arctic sorrel it seems this worked. is the " value_template: >- " the sentence the make multiple lines templating

hollow bramble
#
{% set entities = ['spray_moment_morning', 'spray_moment_afternoon', 'spray_moment_evening'] %}
{% set ns = namespace(value=false) %}
{% for entity in entities %}
  {% if (states('sensor.time') == state_attr('input_datetime.' + entity, 'timestamp') | int | timestamp_custom('%H:%M', False)) and ns.value == false %}
    {% set ns.value = true %}
  {% endif %}
{% endfor %}
{{ns.value}}

I don't know why I thought that would be cleaner, but it could be more readable 🤷

#

or it's garbage and belongs in the trash 🤷

opal dawn
#

Also a nice one ! gives me some inspiring for other stuff. Thx

arctic sorrel
#
sensor:
- platform: template
  sensors:
    temperature_th:
      friendly_name: Temperature
      device_class: temperature
      value_template: "{{ (state_attr('switch.sonoff_1000abcdefg', 'temperature')|int)/100 }}"
``` Try that @thorny snow - replace the entity in there obviously
thorny snow
#

Thank you - I'll give that a try!

opal dawn
#

how do you paste / post the code like you did above here tinkerer?

silent barnBOT
#

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

hollow bramble
#

after the first three ticks you can add a language and it will provide syntax highlighting for said language

arctic sorrel
#

```yaml
blah
```

hollow bramble
#

the list of languages supported is actually pretty impressive

thorny snow
#

Ok I tried the YAML above, with my entity put in, but the value is still showing as it's original - ( I have it as a badge at the moment, but even adding it as an entity card doesn't change it). I'm sure I'm missing a really simple step here to get that template to load?

hollow bramble
#

Did you restart home assistant?

arctic sorrel
#

It won't change the original entity

silent barnBOT
thorny snow
#

Yeah I restarted it after the changes

#

ok let me read those rules over

arctic sorrel
#

Also the part about testing 😉

thorny snow
#

hah, yeah I'm testing it now too, I don't think it's getting the value from the sensor at all in the template

thorny snow
#

ok so testing {{ (state_attr('switch.sonoff_a40000678', 'temperature')|int)/100 }} and {{ (state_attr('sensor.sonoff_a40000678', 'temperature')|int)/100 }}, just comes back with 0.0 on the dev tools test - the value on my badge at the moment shows 2212, so something's not quite right

arctic sorrel
#
{{ state_attr('switch.sonoff_a40000678', 'temperature') }}
``` what does that show?
thorny snow
#

"None"

arctic sorrel
#

There's your problem 😉

#

Either the entity is wrong, or the attribute is wrong

#
{{ states('switch.sonoff_a40000678') }}

and

{{ states.switch.sonoff_a40000678.attributes }}
thorny snow
#

Aha, thanks. So I can get it working without the division on it now, adding the division part changes it from "2212" to 0.0

arctic sorrel
#

Then... your other template is very different to what you've been sharing

thorny snow
#

{{ state_attr('sensor.sonoff_a400006786_temperature', 'temperature') }}
{{(state_attr('sensor.sonoff_a400006786_temperature', 'temperature')|int)/100 }}

Returns
"2212"
0.0

arctic sorrel
#

sensor != switch

#
{{ state_attr('sensor.sonoff_a400006786_temperature', 'temperature') }}
{{ (state_attr('sensor.sonoff_a400006786_temperature', 'temperature')|int) }}
#

Though, I'd expect the state of a sensor called temperature to be a temperature 🤔

thorny snow
#

Casting to an int is forcing it to 0 for some reason:
"2212"
0

arctic sorrel
#

I wonder if the state itself has the quotes in it...

#

That's broken

thorny snow
#

That would probably explain why it's not displaying correctly in the first place, then!

#

{'manufacturer': 'coolkit', 'model': 'ZCL_HA_DEVICEID_TEMPERATURE_SENSOR', 'sw_version': 'NON-OTA-GL v???', 'subDevId': '"9738781b004b1200"', 'parentid': '"1000deebda"', 'temperature': '"2212"', 'humidity': '"7859"', 'battery': '100', 'trigTime': '"1594307996017"', 'cloud': '"online"', 'unit_of_measurement': '°C', 'friendly_name': 'Graysons Room', 'device_class': 'temperature'}

#

yes, it does

arctic sorrel
#

It should be possible to fix that with templates at least, but it's not going to be fun

thorny snow
#

ok cool - this is going to require food and beer

arctic sorrel
#
{{ state_attr('sensor.sonoff_a400006786_temperature', 'temperature').split('"')[1] }}
thorny snow
#

yeaaaasss

#

{{ (state_attr('sensor.sonoff_a400006786_temperature', 'temperature').split('"')[1])|int /100 }}

#

22.12

#

Excellent, thank you so much!

arctic sorrel
#

No worries

thorny snow
#

I'm still going to go and get food, and beer, though

#

Thanks again @arctic sorrel

arctic sorrel
#

I would too

rich stag
#

is there any way to have a template output a non-string? I'm thinking about rest since the data has to be sent as json rather than a string

arctic sorrel
#

Yes

#
{{ states('thing.whatever')|int }}
buoyant pine
#

well yes, but actually no

rich stag
#

so using '{x | tojson }' would work?

buoyant pine
#

templates always return strings even if the output appears to be another data type

rich stag
#

so how does rest work then? else I'm just stuck getting a 400 error

#

can you prime it to expect a string argument?

buoyant pine
#

need more info, what are you trying to accomplish?

#

is this a POST request?

rich stag
#

yup

buoyant pine
#

Content-Type: application/json header

rich stag
#
switch:
  - platform: rest
    name: "TV Sync"
    resource: http://192.168.0.94:5000/tv_sync
    body_on: '{"active": "true"}'
    body_off: '{"active": "false"}'
    is_on_template: '{{ value_json.active }}'
    headers:
      Content-Type: 'application/json'
#

is it literally the order being the issue here?

#

if so the docs might need a slight edit

buoyant pine
#

remove the tojson filter

#

body_on: '{"active": "true"}'

#

similar for body_off

rich stag
#

was doing that earlier, no luck

buoyant pine
#

is that a valid request to make for your TV python/flask program on your PC?

rich stag
#

I'm sending it to a python/flask program on my PC

#

"TV Sync" is just an alias as I have a tv as one of my monitors lol

#

program takes the colour and sends it back to home assistant to set the led strip on the read of my tv

#

this is to make a switch accessible from the overlay for the program

#

I mean I don't know the syntax with which rest sends the request

#

postman is fine with the json in the body, just not as a string ofc

buoyant pine
#

what does curl http://192.168.0.94:5000/tv_sync show

rich stag
#

this being done from the command line on the pi?

buoyant pine
#

or wherever you have a terminal, yeah

#

or just go to http://192.168.0.94:5000/tv_sync in a web browser

rich stag
#

500 error

#
Traceback (most recent call last):
  File "D:\Python\lib\site-packages\flask\app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "D:\Python\lib\site-packages\flask\app.py", line 1953, in full_dispatch_request
    return self.finalize_request(rv)
  File "D:\Python\lib\site-packages\flask\app.py", line 1968, in finalize_request
    response = self.make_response(rv)
  File "D:\Python\lib\site-packages\flask\app.py", line 2097, in make_response
    raise TypeError(
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
buoyant pine
#

does it require authorization at all?

rich stag
#

shouldn't

buoyant pine
#

have you been able to POST to it at all?

#

i'd assume not if it's not accepting GET requests

rich stag
#

postman seemed to do fine

#

although that was from the same machine

#

I did make sure to make a firewall exception though

buoyant pine
#

welp someone smarter than me in this regard will probably need to help

queen meteor
#

500 is internal serve error. It (the server) must be crashing with that request.

buoyant pine
#

i think that's the stack trace above

rich stag
#

still running it would seem

queen meteor
#

It must have passed authentication by then. Unless the error is in the authentication

buoyant pine
#

the call is coming from inside the house

rich stag
#

👀

queen meteor
#

Tried with curl or command line first?

rich stag
#

ngl I don't know how to access command line on my pi in such a way I can use curl

buoyant pine
#

does the ssh and web terminal have curl?

queen meteor
#

It can be from anywhere. Doesn’t have to be from pi - as long as the url is accessible.

rich stag
#

500 server error

#

just to clarify that was from cmd on my laptop on the same network

#

not reiterating old news

queen meteor
#

Then something Is wrong. You need to fix or do some diagnostic on that before doing it from HA.

rich stag
#

hmmm

#

ok cheers

rich stag
#

so I can now curl from the command line on the pi with minimal issues (it actually sends the data at least), literally just the template that doesn't work

#
curl --header "Content-Type: application/json" \   --request POST \   --data '{"active": "true"}' \   http://192.168.0.94:5000/tv_sync
#

although I do get this

Truecurl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
ivory delta
#

That looks pretty Googleable.

thorny snow
#

Not sure if this is for in here, or #frontend-archived - I created a template earlier (thanks to @arctic sorrel !) to correctly format my temperature sensor. I've added that template to my config.yaml, and restarted HA. But I can't see how I get that new template to load, the values showing when I add that sensor (as a gauge, for example, or a badge), are still showing the default value, not the new template value. Am I missing some config somewhere to tell HA to use that new template?

arctic sorrel
#

As I mentioned before.... that template sensor does not replace your original entity

#

You now have another entity

tulip viper
#

hellloo, i wanted to set an input_number when an automation triggers. But it's not working,...

data:
  value: '{{states.sensor.arbeit_home.attributes.duration_in_traffic[0:3]|float}}'
entity_id: input_number.traffic_last_checked
service: input_number.set_value
#

The output of the term in value is 25.0 :/

thorny snow
#

You now have another entity
@arctic sorrel That's where i was getting confused, I couldn't see it on the entity selector, but now I've looked again, I can, it's just not named what I was expecting. But that makes perfect sense now, thanks again!

queen meteor
#

Use data_template instead of data @tulip viper

arctic sorrel
#

No s 😉

queen meteor
#

🤣

silent barnBOT
dreamy sinew
#

Yeah it's a pita on mobile

queen meteor
#

Try template editor on mobile and thank me later 😝

dreamy sinew
#

Heh I might have tried it

queen meteor
#

I cannot figure out a way to clear default text on iPhone in the template editor. That sucks ass.

#

The default text is useless and many people think it is real code and afraid to touch it.

dreamy sinew
#

Hmm, no long press context menu in iOS?

queen meteor
#

No long press.

dreamy sinew
#

Heh gg apple

hollow bramble
#

There is in iOS, just not allowed in code mirror fields

queen meteor
#

It is probably intercepting keyboard or text changed events to render

dreamy sinew
queen meteor
#

Someone try that on iPhone. Doesn’t work like that in iPhone.

#

Can you actually select all and clear text?

hollow bramble
#

You can, but for some reason not in code mirror editors

queen meteor
#

🍏

#

Where is my apple nausea face emoji?

dreamy sinew
#

Actually, apparently not in Android

#

It'll select but you can't clear

#

And the cursor keeps jumping to the head of the file if you type

queen meteor
#

What good does it do if you can select and not clear? 🤣

hollow bramble
#

Copying the very useful sample text 🙂

queen meteor
#

😂

dreamy sinew
#

Lol

hollow bramble
#

You can actually do it on iOS too, as long as the keyboard is closed

queen meteor
#

Hmm. Let me try that

tulip viper
#

thanks for the help.. worked now

warped hornet
#

Is it possible to query entities from a specific integration?

hollow bramble
queen meteor
#

I can’t do shit. Selecting text is a joke.

hollow bramble
#

Kinda anyway

dreamy sinew
#

Yeah the rendering is a mess on mobile. I begrudgingly retract my apple snark

arctic sorrel
#

@warped hornet I'm not aware of any way to do that, I don't think the information is available

warped hornet
#

Hmm, the information is in the frontend, so I would suppose it is there somewhere

dreamy sinew
#

Might be at the device level but entities typically don't care

queen meteor
#

What specific integration? If you have code for it, you can access all the entities

dreamy sinew
#

Unless it's something domain specific

warped hornet
#

It is the ESPHome integration

#

I would like to fetch a list with all my esphome entities

hollow bramble
#

Entity naming convention would make it trivial

queen meteor
#

You might want to think of other way of doing it. That’s not a good practice usually

#

Or do it outside.

warped hornet
#

@hollow bramble yea, that is my current idea, however I don't really like it that way

hollow bramble
#

Where do you see that information in the frontend?

#

Oh in the entities tab, I see

dreamy sinew
#

Probably in the device registry

warped hornet
#

Is it possible to access the device registry in any way?

hollow bramble
#

Nope, everything in templates is reliant on the state machine

queen meteor
#

A simple “clear text” button/link would be nice in the template editor.

hollow bramble
#

(afaik)

queen meteor
#

I hate Ui coding. 😝

hollow bramble
#

Well it hates you too GWspenderHyperMad

queen meteor
#

I am totally happy with that too.

#

<<redacted>> 😂

stone lintel
#

Hi, I'm trying to count the number of media players on at any one time and have this as my template but I'm not sure it's correct as it's not showing a numner in developer tools when I use
{{ states("sensor.media_players_on") }}

   sensors:
     media_players_on: 
        unit_of_measurement: 'on'
        value_template: >
          {% set media_players = [
            states.media_player.kitchen_display,
            states.media_player.living_room_mini,
            states.media_player.living_room_sonos,
            states.media_player.office_sonos,
            states.media_player.bedroom
            ] %}
          {{ media_players | 
selectattr('state','eq','on') | list | count }} ```
ivory delta
#

That's an interesting way to get around the 15 line limit... and somehow takes even more screen space.

hollow bramble
#

did you test the template before putting it in the sensor?

stone lintel
#

It wasnt intentional to do that...

#

the template is based on the same one I have for lights but I changed the reference from lights to media players

#

that one works

hollow bramble
#

K, that doesn't really answer the question though 😉

stone lintel
#

No is probably the answer 🙂

warped hornet
#

@stone lintel I'm working on the exact same thing. I think you need to map your entity_id's to actual entities before applying your filter

stone lintel
#

Thanks, I think I've managed to get it working with
{% set media_players = [states.media_player.kitchen_display, states.media_player.living_room_mini, states.media_player.living_room_sonos, states.media_player.office_sonos,states.media_player.bedroom] %} {{ media_players | selectattr('state','eq','playing') | list | count }}

queen meteor
#

You can simplify even further.

warped hornet
#

@queen meteor How would you map a list of entity_ids (simply strings) to an list of actual entities ?

queen meteor
#

Not sure what you mean. Put them inside states?

dreamy sinew
#

Depending on where this is used, you should probably leave it as it is

warped hornet
#

@queen meteor Such that [<id1>, <id2>, <id3>] would become [<entity obj1>, <entity obj2>, <entity obj3>]

queen meteor
#

If you show the code, someone might help. I think I know what you are trying to do.

#

It is usually never a problem. Just share the code.

buoyant pine
#

usually never

stone lintel
#

You can simplify even further.
@queen meteor oooh how would I do that?

buoyant pine
#

carefully

queen meteor
#

If you have a group, it becomes much simpler.

warped hornet
#

@queen meteor Something like:

{% set hosts = ['bedroom_ceiling', 'coffee_machine', 'fan_power_plug'] %}
{% set entity_ids = hosts | map('regex_replace', '^(.*)$', 'binary_sensor.\\1_status') | list %}
{% set entities = <map entity_id to states(entity_id)> | list %}
queen meteor
#

You can’t convert strings to objects like that unfortunately.

#

Wherever you are going to use entities, you need to figure out a way to use those strings.

warped hornet
#

Yea, ended up with a group instead and this template {{ states|selectattr('entity_id','in',state_attr('group.esphome_hosts_connected_status','entity_id'))|selectattr('state','eq','on')|list|count }}

rain pebble
#

Hello all, need a quick hand with the logic in one of my templates for my HVAC.
I recently gained some roommates and I need HASS to track multiple users to determine what temp the HVAC is set to. Im pretty sure 'home' and 'away' are fine. Im just not sure how to handle the 'near home' portion, where one roommate entering the 'near home' state would not raise the temp on someone thats already home. This is what I have so far.
https://hasteb.in/xapiceci.py

queen meteor
#

there is no near_home state unless you use proximity sensor, and the states are home and not_home

rain pebble
#

there is no near_home state unless you use proximity sensor, and the states are home and not_home
@queen meteor Its a custom zone, and yes it works and has worked fine when it was just me here in the house.

queen meteor
#

ok... custom zone works - if you use proximity sensor you can even tell if the person is traveling towards or away from your home

rain pebble
#

Ill get to that when I get to it. LOL
Right now, Im just trying to get the basics of this thing working.
Updated to correct the 'not_home' section of the data template.
I just need to figure out the logic for 'near_home'
https://hasteb.in/eyixohuy.py

queen meteor
#

use long/lat for custom zone, and use zone enter and zone leave events to know if you are near a zone

#

use that as a trigger point - you could also use for: x minutes to ensure they are in that zone and not just passing through

rain pebble
#

Thats fine and all, I just trying to figure out how to do that for multiple people.
What I dont want happening is someone to be home, and another person enters the near_home zone, and the HVAC turns up the temperature.
The logic 'or' logic makes sense in the template for determining if "anyone" is home.
The 'and' logic makes sense in the template for determining if "everyone" is not home.
I just can't seem to figure out the logic for writing out the 'near-home' without it causing conflicts with anyone being home.

queen meteor
#

I understand. Best way to do that is use input booleans, and toggle them based on who is at home. Use those input booleans in the automation - that way you can decouple things, and do it cleanly.

#

you can also use those input booleans for other reasons - like turning on/off home security system, turn lights on/off..etc

rain pebble
#

So write a condition to not do anything if someone is home using the input booleans?

queen meteor
#

yup

rain pebble
#

Ok thanks

trim leaf
#

Hey all, can I access state timestamp data from templates? For example I want to be able to only do something in a template sensor if a input_boolean has been set to true for x minutes

#

Something like: if input_boolean is true for 10 minutes then get temp data from entity_1

#

it feels like I am trying to do something that I shouldnt be doing in templates, but wanted to see

inner mesa
#

That sounds like an automation with a ‘for:’ clause

silent barnBOT
trim leaf
#

@inner mesa yeah I use that often but I need to be able to set the active state of a sensor entity

#

sorry, I should have mentioned that I am trying to use this within a template sensor

#

I am trying to take the highest temperature from various sensors and store it in a sensor template. The catch is I want to only use sensor data if my input boolean has been set to true for x minutes

inner mesa
#

You don’t really ‘store’ things in a template sensor

trim leaf
#

right, I guess I mean I want the "state" of the sensor to be from a specific sensor

#

based on input_bool behavior/offsets

inner mesa
#

You can store the max of a bunch of things in an input_number

#

And use the trigger I mentioned

#

I’m wondering if the focus on the template sensor is overlooking a diff solution

#

I’m not convinced that you do what you want with just a template sensor

trim leaf
#

I am using template sensor since I eventually want to use it in the generic_thermostat as the source temp

#

although I think youre onto something, maybe I store the number in input_number, do all the logic using automations, then just render that input_number into a template sensor (instead of trying to do all the logic in templates)

inner mesa
#

Won’t any entity with a number work?

trim leaf
#

let me check!

inner mesa
#

Yeah, that’s how I would do it

trim leaf
#

entity_id for a temperature sensor, target_sensor.state must be temperature.

inner mesa
#

So the problem is units, or a type?

trim leaf
#

its a bit unclear to me, but if I do it using a template sensor then I can just make whatever the input_number is be in degrees F

inner mesa
#

Units are just a string. They don’t mean anything

trim leaf
#

ohhh