#templates-archived

1 messages Β· Page 135 of 1

ivory delta
#

They're used by the UI. πŸ€·β€β™‚οΈ

#

They're stored with the code for the integration because they're specific to the integration.

#

You're welcome to search for evidence of a binary sensor showing anything other than 'on' or 'off' in the Dev Tools. It doesn't change at all, regardless of your language settings.

#

πŸ€·β€β™‚οΈ

#

Some components and platforms will have strings that need to be localized specifically for that platform. These strings are managed in the core home-assistant repository. The Home Assistant backend will serve strings to the clients based on the loaded components in the running instance.
https://developers.home-assistant.io/docs/internationalization

#

I don't know what you know that I don't. Please share.

mighty ledge
#

it is true unfortunately

crisp storm
#

:/

mighty ledge
#

just copy the state dict into your template from the file you linked and use the device_class to pull the translation

clever fable
#

I'm having trouble with this Template Sensor. It seems no matter what I have tried to fix it I cant get it to pass the check.

#
  sensors:
    living_room_occupied:
      value_template: >-
        {{ is_state('binary_sensor.front_door_contact', 'on')
           or is_state('binary_sensor.living_room_motion_occupancy_north', 'on')
           or is_state('binary_sensor.living_room_motion_occupancy_south', 'on')
           or states('sensor.living_room_grideye_occupancy_count')|float > 0 }}```
inner mesa
#

you're not following the syntax from the docs

clever fable
#

I'm not?

#

I looked at the docs

#

and I have another Template sensor that passes

#

I'll look again

inner mesa
#

so that's the legacy version

#

where did you put that?

clever fable
#

Wow I wasn't even close

#

I guess I need to create a template: section and start over

#

This also explains alot

inner mesa
#

I don't think you were too far away, you're just using the legacy version

#

so where did you put that?

#

there's nothing wrong with the legacy definition - all of mine are that way

clever fable
#

I had it in binary_sensors:

#

I have now moved it to template:

#

Is that right?

#

This is what I have now... - binary_sensor: - name: living_room_occupied value_template: >- {{ is_state('binary_sensor.front_door_contact', 'on') or is_state('binary_sensor.living_room_motion_occupancy_north', 'on') or is_state('binary_sensor.living_room_motion_occupancy_south', 'on') or states('sensor.living_room_grideye_occupancy_count')|float > 0 }}

inner mesa
#

it should have been under binary_sensor:, not binary_sensors:

#

no, not quite

#

state: >-

clever fable
#

I typed it wrong

#

that is where I had it

#

so no longer value_template

inner mesa
#

as in the docs

#

you should really focus on the error, rather than just arbitrarily changing it

clever fable
#

Well I cant get the syntax to pass right now so I'm at least trying to do that first

inner mesa
#

if it doesn't pass, then there's an error. focus on that

clever fable
#

Yeah thats what I'm doing

#

now

#

looks like its passing and working now thanks

edgy umbra
#

Can anyone explain why this template always shows 9 sep instead of the actual data of today (15 sep).

#

{{ as_timestamp(states('sensor.date')) | timestamp_custom('%-m %b %Y') }}

#

The sensor.date works fine btw.

inner mesa
#

It’s the 9th month

#

Did you want %d?

edgy umbra
#

Ok that's embarrassing. Thx Rob πŸ™‚

red zenith
#

Hi, I am look for some help.
I am trying to compare the current and previous value of a sensor is there a easy we of doing this?
Can I do something like sensor.name-of-sensor. previous.value

What I am trying to achieve is to find out if the sensor has gone up, it which case I would like to add the difference to a another sensor or if it has gone down add the value to an another sensor.

rugged laurel
#

{{ trigger.from_state.state }} <-- previous
{{ trigger.to_state.state }} <-- new

red zenith
#

Thanks @rugged laurel I am struggling to understand how to use them.
If I have a sensor called** sensor.kwh** and I want to get the difference between the current and previous values how do I related the** trigger.from_state.state** and** trigger.to_state.state staments**.

rugged laurel
#

Maybe the trigger based template sensors can do that as well πŸ€·β€β™‚οΈ

red zenith
#

I was thinking of using a custom sensor set up in the my configuration.yaml (sorry if I am doing this the wrong way I as still getting head around it)

silent barnBOT
arctic jay
#

Anyone can help me?

median mason
#

I have 3 sensor entities (temp, humidity, pressure) from a aqara temperature and humidity sensor. i tried following code, but i got error "Invalid config for [sensor.template]: [attributes] is an invalid option for [sensor.template]. Check: sensor.template->sensors->balkon_climate->attributes. (See ?, line ?)."

- platform: template
  sensors:
    balkon_climate:
      friendly_name: "Balkon Climate"
      device_class: temperature
      unit_of_measurement: 'Β°C'
      value_template: "{{ states('sensor.temperature_balkon') }}"
      attributes:
        temperature: "{{ states('sensor.temperature_balkon') }}"
        humidity: "{{ states('sensor.humidity_balkon') }}"
        pressure: "{{ states('sensor.pressure_balkon') }}"
ivory delta
arctic jay
#

Mr. @ivory delta are you talking to me? or to arifroni?

mighty ledge
silent barnBOT
mighty ledge
#

also, as mono suggested, you should move to the new implementation of template sensors

arctic jay
median mason
# mighty ledge attributes should be attribute_templates]

thanks, it works with attribute_templates. I mixed up with new and old implementations. now I am converting all old implementations to new ones. i noticed, there is no 'friendly_name' in the new implementation. how can I achieve that? For example in this case

template:
  - sensor:
    - name: hue_toilet_motion_sensor_battery
      unit_of_measurement: '%'
      state: "{{state_attr('binary_sensor.hue_motion_sensor_1_motion', 'battery_level')}}"
mighty ledge
#

name is friendly_name

#

use unique_id to set the object_id

blazing burrow
#

anybody that can offer some wisdom on templating the navigation_path for a tap action in lovelace?

mighty ledge
#

you can't template the frontend

#

there are custom cards that allow you to template things, but that's it. Only built-in card that can be templated is the markdown card

blazing burrow
#

i have successfully used custom:card-templater before

#

and am trying now, but it's not doing what i expect, even per the docs for that card

mighty ledge
#

πŸ€·β€β™‚οΈ you'd have to post configuration

blazing burrow
arctic jay
#

Hi there again, as @mighty ledge suggested i tried to use rest integration and not rest sensor. I still cannot get the correct value.
Am I using it correctly? can use attributes like this? dataList[2]???

#

Anyone can confirm this?

ivory delta
#

json_attributes string | list (optional)
A list of keys to extract values from a JSON dictionary result and then set as sensor attributes.

#

The key names. Not paths to anything beneath those keys.

#

You probably need to create multiple sensors instead. States are more useful than attributes anyway.

arctic jay
#

every dataList[X].value have a value that i need, and the X goes from 1-30. Do i need to create 30 sensores? I will need to get information from the API 30x every 300 seconds... ?

ivory delta
#

That or create a custom integration πŸ€·β€β™‚οΈ

mighty ledge
#
rest:
- ... all your setup junk ...
  sensor:
  - name: sensor 1
    value_template: "{{ value_json.deviceType }}"
  - name: sensor 2
    value_template: "{{ value_json.dataList[19] }}"
  - ... etc ...
arctic jay
#

sry for my dumb and lazy person

distant plover
#

Is there a simple way to have the last word say 'time' when result is 1 and else 'timer'?

    state_attr('input_datetime.vaskemaskin_startet', 'timestamp')) |
    timestamp_custom('%H') |int }} timer.```
mighty ledge
#

set the result equal to a variable and use almost what you have written in your sentence

#

Iknow you know how to do this, you've asked questions many times here before

#

start with the first part. How do you set something to a variable? There's literally hundreds of thousands of examples

#

start simple, just set something like x equal to 1

distant plover
#

I think I found a different way but it might be silly:

    state_attr('input_datetime.vaskemaskin_startet', 'timestamp')) |
    timestamp_custom('%H') |int == 1%}1 time{% else %}{{ (now().timestamp() -
    state_attr('input_datetime.vaskemaskin_startet', 'timestamp')) |
    timestamp_custom('%H') |int }} timer. {% endif %}
mighty ledge
#

yep that will work, but if you just learned how to set something, it would be alot smaller. Either way, you do you

distant plover
#

But you still meant using if and else? Like so?

    state_attr('input_datetime.vaskemaskin_startet', 'timestamp')) |
    timestamp_custom('%H') |int %}
Vaskemaskiiinen er nΓ₯ ferdig etter {% if vaskemaskin_timer == 1%}1 time{% else %}{{ vaskemaskin_timer }} timer. {% endif %}```
mighty ledge
#

yah but you can use inline if statements, which is almost word for word what you typed

#

you said " say 'time' when result is 1 and else 'timer'?"

#

{{ 'time' if vaskemaskin_timer == 1 else 'timer' }}

#

literally almost word for word

#

just sayin πŸ˜‰

ivory delta
#

More concise and easier to read too smart2

distant plover
#

Ah. Thanks!

rugged laurel
#

You got a few i to many in "Vaskemaskiiinen"

distant plover
#

It's because of the cloud_say service. For some reason that's the only way it will say it properly. πŸ˜„

#

Same with tumble dryer (tΓΈrketrommelen) that needs to be spelled 'tΓΈrke-trommelen'. Otherwise it puts in a 'u' instead of 'o'.

blazing burrow
#

trying to figure out a template to give all automations which triggered within x amount of time

#

any ideas?

ivory delta
#

What have you tried?

rugged laurel
ivory delta
#

As a hint... seems easy to grab all the automations and run them though rejectattr.

distant plover
edgy umbra
#

How stupid is this template? I mean, is there a better way doing this. πŸ™‚

#
{% if lights|length == 0 %}
{{ 'Verlichting staat uit' }}
{% elif lights|length == 1 %}
{{ '1 lamp aan' }}
{% elif lights|length == 2 %}
{{ '2 lampen aan' }}
{% elif lights|length == 3 %}
{{ '3 lampen aan' }}
{% endif %}```
ivory delta
#

To get lamp vs lampen?

edgy umbra
#

Yeah i want to show 1 light on, 2 lights on, etc and if lights off "Lights Off".

#

But i'm not skilled in this so that's the easiest way i can found for me. πŸ™‚

ivory delta
#

In your language, how many numbers would use 'lamp'?

edgy umbra
#

One

ivory delta
#

Right... so that's the only special case to cover.

edgy umbra
#

1 lamp or 2 lampen

ivory delta
dreamy sinew
#

and if you don't care about the object_ids anymore you can pare down your set

#

drop the map

edgy umbra
#

Haha that's to much for me phnx, i just "stole" your template from yesterday and changed it a bit. πŸ˜„

#

Maybe i just keeps this because it works and otherwise i will make it worse it think...

ivory delta
dreamy sinew
#

{{ '{} lamp{} aan'.format(lights|length, 'en' if lights|length > 1 else '') }}

edgy umbra
#

Where will this be placed in the template?

#

If i do it like this it says "0 lamp aan" but there are "3 lampen aan".

#
{% if lights|length == 0 %}
{{ 'Verlichting staat uit' }}
{% elif lights|length == 1 %}
{{ '1 lamp aan' }}
{% elif lights|length == 2 %}
{{ '2 lampen aan' }}
{% elif lights|length == 3 %}
{{ '3 lampen aan' }}
{% endif %}```
ivory delta
#

That isn't supposed to be the first line. It's supposed to replace the numerous ones beneath.

blazing burrow
#

how do i get the last triggered from a datetime into a float so i can compare to now? basically

ivory delta
#

Well that's not going to be testing the last_triggered anyway. You want 'attributes.last_triggered'.

dreamy sinew
#

leave them both as datetime objects and compare directly

blazing burrow
#

i want to do something like "all automations that triggered in the last 5 minutes"

#

so i think i need to do now - 300s and reject anything greater than that

blazing burrow
ivory delta
#

Try it yourself. Simplify it so you can see it a step at a time.

blazing burrow
#

well i can see that last_triggered is an attribute of the entities

ivory delta
#

What does this give you?
{{ expand(states.automation) | map(attribute='last_triggered') | list }}

blazing burrow
#

a bunch of undefined

ivory delta
#

And how about this?
{{ expand(states.automation) | map(attribute='attributes.last_triggered') | list }}

blazing burrow
#

so if i put attributes.last_triggered i get datetimes

ivory delta
#

Jinja doesn't know what HA attributes are. You have to tell it where to look...

blazing burrow
#

ok but for example this isn't right syntax: rejectattr(attribute='attributes.last_triggered', '>', now())

ivory delta
#

No, it's not. What's it telling you?

blazing burrow
#

TemplateSyntaxError: invalid syntax for function call expression lol

mighty ledge
#

you don't need the expand

blazing burrow
#

and this: rejectattr('attributes.last_triggered', '>', now())

#

gets me TypeError: '>' not supported between instances of 'NoneType' and 'datetime.datetime'

mighty ledge
#

{{ states.automation | map(attribute='attributes.last_triggered') | list }}

blazing burrow
#

because i have a bunch of undefineds in there

ivory delta
#

Nothing to do with undefined...

#

If you're using rejectattr('attributes.last_triggered'..., they're not undefined.

#

You just proved that by using a map to see the values.

blazing burrow
#

seems to me that rejectattr and map have different syntax

ivory delta
#

what they're looking for is the same.

mighty ledge
#

map, requires you to explain what you want to map

#

rejectattr and setattr expect attributes, so you don't need attribute=""

#

so yes, the syntax is different

ivory delta
#

But you still need 'attributes.', which is what they're disputing.

mighty ledge
#

yes, because that's the attribute

ivory delta
#

See for yourself, drinfernoo:
{{ states.automation | selectattr('attributes.mode', 'eq', 'parallel') | list }}

#

Works fine. Syntax isn't the problem.

#

The comparison is, which is what it's telling you.

mighty ledge
#

in map you'd need attribute='attributes.last_triggered'

#

in selectattr/rejectattr you just use 'attributes.last_triggered'

blazing burrow
#

ok

mighty ledge
#

the attribute doesn't change between the 2 methods

blazing burrow
#

so i need to figure out the comparison

mighty ledge
#

well, nothing is going to be > now()

#

so your logic is flawed

blazing burrow
#

yeah i know that

#

i'm just trying to get a tempalte that "works" atm

mighty ledge
#

to do what

blazing burrow
#

not error lol

ivory delta
#

i want to do something like "all automations that triggered in the last 5 minutes"

blazing burrow
#

^

#

so like this: {{ states.automation | rejectattr('attributes.last_triggered', '>', (now() | float) - 300) | list }}

#

but last_triggered is obv not a float

mighty ledge
#

{{ states.automation | rejectattr('attributes.last_triggered', <, now()-timedelta(minutes=5)) | map(attribute='entity_id') | list }}

#

but you might have to reject missing last_triggereds

blazing burrow
#

{{ states.automation | rejectattr('attributes.last_triggered', '<', now()-timedelta(minutes=5)) | map(attribute='entity_id') | list }}

TypeError: '<' not supported between instances of 'NoneType' and 'datetime.datetime'

ivory delta
blazing burrow
#

yeah umm

#

{{ states.automation | rejectattr('attributes.last_triggered', 'eq', none) | rejectattr('attributes.last_triggered', '<', now()-timedelta(minutes=5)) | map(attribute='entity_id') | list }}

#

seems to do it

ivory delta
#

Just for semantics, I'd suggest going with this:
{{ states.automation | rejectattr('attributes.last_triggered', 'eq', none) | selectattr('attributes.last_triggered', '>', now()-timedelta(minutes=5)) | map(attribute='entity_id') | list }}

#

The fewer negatives, the better. Easier to understand when you want to read it in a few months.

dreamy sinew
#

sounds like a lesson learned the hard way πŸ˜›

blazing burrow
#

ah yeah ok

#

i could also do selectattr when ne to none right?

ivory delta
mighty ledge
#

I like to think in double negatives

ivory delta
mighty ledge
#

its not never the correct way to do things

blazing burrow
#

ok so... now i'm stuck again on how exactly to use this for what i want

#

i'm using it in a template filter for custom:auto-entities

#

but i want to pass options to the entity row as well

#

which is setting options: ... for include: and exclude: filters

#

but for a template filter i have to return the whole entity object

ivory delta
#

So return the objects.

#

Just don't map the entity ID...

#

The base form of your 'get every automation from the last X minutes is something like this:

  | rejectattr('attributes.last_triggered', 'eq', None) 
  | selectattr('attributes.last_triggered', 'gt', utcnow()-timedelta(minutes=60)) 
  | list 
}}```
#

Map what you want out of it when you need it. Otherwise, that's just a list of state objects.

#

(also, bonus points for formatting it to be easy to read πŸ˜‰ )

mighty ledge
#

I thought there was a way to map that properly with auto entities where it uses the entity_id and it's mapped to properly place it in the object

blazing burrow
#

well i mean it gives me the entity ids which is fine

mighty ledge
#

I can't remember tho because I haven't used that in like 2 years, ditched it for lovelace_gen

blazing burrow
#

but like for example:

filter:
  include:
    - domain: light
      state: "on" # Remember that "on" and "off" are magic in yaml, and must always be quoted
      options:
        tap_action:
          action: toggle
#

that is an example FROM github

#

not mine

#

but i need to pass the options: block as well

#

and template: filter doesn't support that

#

so i think my template needs to include all those options?

#

frick idk

ivory delta
mighty ledge
#

pretty sure you just apply that filter after your entity_id filter

blazing burrow
#

feel like this template still isn't right

ivory delta
#

What does it output?

blazing burrow
#

nothing... testing in template editor and a bit sutck

#

well, i shouldn't say nothing

ivory delta
#

It'll tell you what's wrong...

blazing burrow
#

doesn't show any entities in the card

ivory delta
#

Put it in the Dev Tools. Tell us what it shows.

blazing burrow
#

it tells me

TemplateSyntaxError: unexpected '%'

ivory delta
#

Right. Because you have a template inside a template. That's invalid.

blazing burrow
#

ok

ivory delta
#

I have no idea what you think you're referring to with config.entity either.

blazing burrow
#

yeah, i changed it to id

#

for id in ids

ivory delta
#

Nor do I know what you're trying to do with having a | inside a string.

blazing burrow
#

took those out too

#

works now in dev tools but

ivory delta
#

And the | before an object for tap_action? sus_think

ivory delta
#

Now you have strings that span multiple lines, rather than multiline templates...

#

But if it works...

blazing burrow
#

well it shows me stuff in dev tools

#

but obv lovelace not liking it

ivory delta
#

template: | probably has something to do with it.

#

Why not template: >?

blazing burrow
#

ah well didn't change anything

#

i had used | because of

#

something

#

idr

#
type: custom:auto-entities
card:
  type: entities
filter:
  template: |
    {% for light in states.light %}
      {% if light.state == "on" %}
        {{ light.entity_id}},
      {% endif %}
    {% endfor %}
#

that

#

from auto entities docs

#

actually when i changed it to >, it changed it back to | when i saved

charred dagger
#

Make sure that when you test it in dev-templates it says "Result type: list"

blazing burrow
#

ohhh it's counting all my commas as a new list item

charred dagger
#

That requires some trickery with quotes and stuff. This works, for example: {%- set ids = states.automation | map(attribute='entity_id') | list -%} [ {% for id in ids -%} { "entity": "{{id}}", "secondary_info": "last-changed", }, {%- endfor %} ]

blazing burrow
#

wait what?

#

sorry, i'm missing something

charred dagger
#

And since the results you want includes templates, you also need {% raw %} {% endraw %} in some places.

ivory delta
#

🐰 πŸ•³οΈ

blazing burrow
#

so raw/endraw should basically go around any of my "inner" templates?

#

around the whole thing or around each line?

#

inside or outside of quotes?

charred dagger
#

And then there's the newlines...

#
[
{% for id in ids -%}
{
  "type": "custom:template-entity-row",
  "state_color": "true",
  "secondary": "{%raw%}{%- if state_attr(id, 'last_triggered') -%}{{ relative_time(state_attr(id, 'last_triggered')) }} ago{%- else -%}Never triggered{%- endif -%}{%endraw%}",
  "state": "{%raw%}{%- if state_attr(id, 'current') == 0 -%}Not Running{%- else -%}{{ state_attr(id, 'current') }} Running{%- endif -%}{%endraw%}",
 "tap_action": {
   "action": "navigate",
   "navigation_path": "/config/automation/trace/{{ id.split('.')[1] }}"
  }
},
{%- endfor %}
]```
blazing burrow
#

hmm ok lemme see

charred dagger
blazing burrow
#

actually ended up not needing the raw/endraw or removing newlines

#

it was the quotes around my tap_action json

#

simply removing those made it resolve as a string

#

and my card works πŸŽ‰

blazing burrow
#

seems auto entities sort doesn't work with template filter either

silent barnBOT
#

@blazing burrow When using Discord's Reply feature it defaults to pinging the person you reply to, which can get frustrating for the target. Click @ ON to @ OFF to stop this - on the right side of the compose bar.

You have to change this every time (thank the Discord devs for that).

blazing burrow
#

yeah I clicked it too fast 😨

ivory delta
#

If you want to sort, sort before you start looping.

#

There's a Jinja filter for sort.

blazing burrow
#

ah ok, works similar to map/selectattr/etc?

#

I'll look it up, nvm

ivory delta
#

There's a reason we have pins for the common questions πŸ˜‰

blazing burrow
#

ayyy built in filters lol

#

it worked, thanks 😁

ivory delta
#

Filters are powerful once you understand how to combine them.

blazing burrow
#

I'm learning... slowly

#

haven't done many of those more complex ones

vital comet
#

hoi, i need a tiny bit of help

state: "{{((states('sensor.lux_ups_time') | float + states('sensor.caitlyn_ups_time') | float ))}}"

If i put / 6000 at the end will it actually divide the whole thing of do i need to do something different?

ivory delta
#

If you just add it to the end, it'll divide the last number.

inner mesa
#

Try it in devtools -> templates

ivory delta
#

You need to wrap them in parentheses to ensure the division happens last.

vital comet
#

but just putting the / 6000 after brackets should work? HAS has many times screwd my brain process before

inner mesa
#

Try it and see

vital comet
#

as helpfull as that may be some come here to get a quick and simple answer...not "try a billion times and see what works" ^.^
Thanks for the help @ivory delta

ivory delta
#

Did you get it figured out?

vital comet
#

yep just the brackets as you said ^.^

inner mesa
#

Sigh. You can try something like that in much less time than it takes to post in devtools -> Templates. That’s my point

#

β€˜What will it do if I do this?’ Are easily answered there

vital comet
#

but once someone has asked you can probably answer them in a normal way rather than say to find it out the hard way....idk at least that would be more helpful in my opinion(if not helpful than at least nice and polite), Thanks for all the help and ima hop out till i need something again

vital comet
#

also how do i use an entity from a template in the energy thini?

pliant dagger
#

Got a qq here. I have a value template that I'm trying to figure out with a water sensor. I've been racking my brain with this one but the sensor in HA always reports Unknown. Even though the entity is reporting a 0

  sensors:
    laundry_room_wet_sensor:
      friendly_name: "Laundry Room Water"
      value_template: >-
        {% if is_state('number.basement_water_sensor_basic',  255) %}
          wet
        {% elif is_state('number.basement_water_sensor_basic',  0) %}
          dry
        {% else %}
          n/a
        {% endif %}```
#

I'm sure I'm missing something dumb

#

yes I've tested this out in the developer tools with success so I'm not sure whats missing in transit

inner mesa
#

States are strings and you’re comparing the state to a number

pliant dagger
#

I was wondering if that was it

#

sorry the number item is new to me

inner mesa
#

It’s confusing. The state of a number.xx entity is a string

pliant dagger
#

ok so wrap the 255 in single ticks

inner mesa
#

Yes

#

And the 0

pliant dagger
#

lol all I wanna know is if the hoses on the washer bust

#

and of course turn off the water if that happens

#

neighbor had that happen to them and ever since I've been like I need to automate this

#

ok so got that in there now but the template entity still reports it as Unknown even though thats not one of my values

#

Correction it just changed over to n/a

#

and I can confirm that the device is reporting in the 255

2021-09-15 23:36:21.255 INFO ZWAVE: Node 41: value updated: 32-0-currentValue 0 => 255``` from zwavejs logs
#

and I can see the number entity in HA change to 255 but the template will not update

autumn grotto
#

hopefully a quick one for someone:

I've got an input_datetime helper set to 05:15, but {{ (state_attr('input_datetime.climate_start','timestamp')) | timestamp_custom('%I:%M %p') }} gives me 03:15 PM

developer tools output:

editable: true
has_date: false
has_time: true
hour: 5
minute: 15
second: 0
timestamp: 18900
friendly_name: Climate Start

I'm sure there's something I'm missing, but what...?

autumn grotto
terse yoke
#

Hi guys, How could I pull light color value to variable, so I can use it for something else in automation later on? I tried below way (and few modifications with and without quoting), but it is not working. I get "Message malformed: extra keys not allowed @ data['variables']

#

platform: state entity_id: light.lampkidsroom_1 variables: color_name: > {% states.light.lampkidsroom_1.attributes.rgb_color }

#

thx

inner mesa
#

Right, that’s bad syntax

#

Why a variable? Can’t you just refer to the attribute?

terse yoke
#

Yes, I know that. I am not skilled with codding, but I'm "swimming" when have right syntax :)

terse yoke
inner mesa
#

I can’t really figure out what you’re trying to do there. If you want to use the value of an attribute as data to a service call, then you just use {{ state_attr(β€˜light.lampkidsroom1’, β€˜rgb_color’) }}

terse yoke
#

Yes, I want to use rgb value of one bulb to set that rgb value on another bulb with service call light.turn_on

#

Will try with your propose above

inner mesa
#

Right, so you do it that way

terse yoke
#

Thx

wraith kernel
#

Hello all. I have a question. I created statistics for a sensor, and then I want to get the statistics attribute for this sensor to use in automation. But for some reason the attribute is constantly "unknown"

`- platform: statistics
name: "CO2_white_stat"
entity_id: sensor.CO2_white

  • platform: template
    sensors:
    co2whitechange:
    friendly_name: "CO2 white change"
    value_template: "{{ state_attr('sensor.CO2_white', 'change') }}"`

use in UI sensor co2whitechange does not output number
but on the main sensor I get all the statistics data, they are collected and displayed, but I cannot take one attribute separately
Please tell me what I did wrong?)

fossil venture
#

Also entity ids never have capital letters.

#

Also, also you probably don't need a template sensor for this. Numeric state triggers and conditions can access attributes.

wraith kernel
tacit arch
#

Hello, I have a sensor on home power consumption, not on the meter, so I should use a template to create a new energy sensor
I need something like
if ( consumed power > produced power )
return consumed power - produced power
else
return 0
could you help me? Thanks

dreamy sinew
#
{% set diff = states('sensor.consumed_power')|float - states('sensor.produced_power')|float %}
{{ diff if diff > 0 else 0 }}
#

replace those 2 sensors with your actual sensors

tacit arch
#

surely my fault, but Error loading /config/configuration.yaml: while scanning for the next token
found character '%' that cannot start any token
in "/config/configuration.yaml", line 123, column 26

#

sensor:

  • platform: template
    sensors:
    power_taken_grid:
    friendly_name: Energia Prelevata Rete
    value_template: {% set diff = states('sensor.power_home_energy_power')|float -
    states('sensor.power_powerplant_energy_power')|float %}
    {{ diff if diff > 0 else 0 }}
    device_class: energy
    unit_of_measurement: "kW"
ivory delta
#

Either have your template on a single line and wrap it with quotes, or use multi-line templates.

mellow pulsar
#

here is the link to the config yaml I am using.

silent barnBOT
mellow pulsar
#

I believe I have only modified the name, and the states names to reflect changes for my HA instance.

#

I am getting the following error when trying to start ..

#

The system cannot restart because the configuration is not valid: Error loading /config/configuration.yaml: while parsing a block mapping in "/config/configuration.yaml", line 1, column 1 expected <block end>, but found '-' in "/config/configuration.yaml", line 692, column 1

#

692 in my config yaml is at the end of the section above for a different entity and it is ok.

#

help! πŸ™‚

tawny locust
#

can someone help me with this 'template'
Game: [[ if(sensor.lich_XXXX.attributes.game == null, "") ]]

#

i want that "null" should be clear, but when its not "null" it should show the state

mellow pulsar
#

instead of using null, use ''

#

for empty string

#

that is 2 single quotes

tawny locust
#

Result is this for now:

Game: [[ Template matching failed: if(sensor.lich_5769.attributes.game == null, "") ]]

tawny locust
ivory delta
#

That doesn't look like Jinja.

tawny locust
#

how can i make it better ?

ivory delta
#

Well... what is it? It's not Jinja. Are you trying to write JavaScript for a #frontend-archived card?

tawny locust
#

i think so

ivory delta
#

.share the whole thing

silent barnBOT
tawny locust
ivory delta
tawny locust
#

hmpf

floral shuttle
#

posted this value_template {{value|round(2) if value < 2500 else 2500}} in #devs_zwave-archived as a possible but hacky way to protect my mqtt sensors in Ha from hysterical spikes. I know you say prevent sh*t from the source, but there's no way. So will test this for some time. Just asking here if this template could be written with other jinja tools/function/filter to set a ceiling value?

ivory delta
#

Sure, use min.

#

The list of available filters is in the pins.

floral shuttle
#

also, to prevent a spike from lets say 200000kWh while it needs to be 34 kWh ( I kid you not) Id consider a value_template to check if the new value is smaller than +10%, and if not, remain with the old value. Would this do: {% if value > states(entity_id) * 1.1 %} {{ states(entity_id) | round(2) }} {% else %} {{ value | round(2)}} {% endif %}

ivory delta
#

And what if there's a genuine reason for an increase greater than 10%?

floral shuttle
#

I dont think that will ever happen on a kWh sensor, but maybe I could set it a bit higher

#

final question, and this might be the most difficult, are negative dents of the same size on the kWh sensors. I could simply use value < states(entity_id) * 1.1 or another number, but would need to take a true reset into account. Maybe exclude the value == 0 situation?

ivory delta
#

I still think you're overthinking it. What's the highest legitimate value you've seen, and have any spikes been less than that?

floral shuttle
#

well, yes, its a bit weird but right now I see a kWh sensor which should grow from 847 onward, had a dent to 0.7 this morning and shortly after that returned to 847+..likewise I have the mentioned spike from 32.25 to 167804.41 back to normal 32,34 ... so yeah these are pretty wide ranged issues...

#

btw the first one would be {{min(value|round(2), 2500)}}? nice!

ivory delta
#

Personally, I'd do it the other way round. Pipe a list into the filter... but same thing.

ivory delta
pastel moon
#

Hi guys. Trying to understand how to use a for loop, but I fail to make it return entity_id's. What am I missing? ```

  • service: script.turn_on
    data_template:

entity_id: ['script.hallway', 'script.kitchen', 'script.living_room']

  entity_id: >                                                                          
    [{%- for room in ['hallway', 'kitchen', 'living-room'] -%}                          
      script.{{ room }}                                                                 
     {% endfor %}]```
#

the commented out line works, and does what I want. I'd like the loop to do that as well, but....

inner mesa
#

It’s curious syntax

pastel moon
#

I saw it in the chat some time ago and thought I'd save it for later...

inner mesa
#

You saw that?

pastel moon
#

An example using this technique. So basically, the loop needs another syntax?

#

I have of course added my entities to it, but other than that just left out an if statement I don't need

inner mesa
#

one way:

#
{% set rooms = ["foo", "bar", "blah"] %}
{% for room in rooms -%}
  script.{{room}}{{", " if not loop.last }}
{%- endfor %}
#

-> script.foo, script.bar, script.blah

#

I don't think you can embed a template in square brackets to form a list like that

pastel moon
#

Oh! Thank you. No, the trace just printed the whole thing, so did not get interpreted correctly. Will test your code πŸ™‚

inner mesa
#

ooh, even better:

#

{{ ["foo", "blah"]|map('regex_replace', '^', "script.")|list|join(', ') }}

#

I like that a lot

pastel moon
#

Works very nice! Thanks! πŸ‘

inner mesa
#

that last one is very sexy

pastel moon
#

I'll try that too, agree, like the compact syntax πŸ™‚

inner mesa
#

-> script.foo, script.blah

pastel moon
#

Perfect! I use this a lot, so will be very useful! Thanks πŸ™‚

floral shuttle
floral shuttle
#

can only get a working template if I float states(entity_id) which makes that 0 in case of unknown. So basically useless....

charred dagger
#

If states(entity_id) | float * 0.1 return 0 then your state was either 0 or nullish and then it would make perfect sense.

floral shuttle
#

yes, but the state wasnt 0 or nullish... I am trying to do this {% set old = states(entity_id) %} {% set new = value %} {% if old == 0 and new < 2 %} {{new}} {% elif new > old * 1.5 or (new < old and value != 0) %} {{old}} {% else %} {{new}} {% endif %}

charred dagger
#

I never used entity_id in mqtt sensors, so I don't know how or if they work

floral shuttle
#

I thought that's how I have to explain the example in the mqtt docs

charred dagger
#

What is your old value?

floral shuttle
#

Not sure... the one before the current πŸ˜‰

mighty ledge
#

Pretty sure that var doesn’t exist

floral shuttle
charred dagger
floral shuttle
#

As I read that example, states(entity_id) is kind of a from_state and value is the to_state .. kind of

floral shuttle
#

I was able to use the example template on a temp entity, and noticed it was unavailable at first, but after an update started to show. however, when using even {% set old = states(entity_id) %} {{old}} on my energy sensors (which have updated while I waited) they remain unavailable after mqtt reload, and unknown upon HA restart.

mighty ledge
floral shuttle
#

was just experimenting with {% if old == None %} {{new}}

mighty ledge
#

but new doesn't exist

floral shuttle
#

but that remains unknown too.... new is value

mighty ledge
#

and you're missing the endif

floral shuttle
#
      {% set new = value %}
      {% if old == None %} {{new}}
      {% elif old == 0 and new < 2 %} {{new}}
      {% elif new > old * 1.5 or
                     (new < old and new != 0) %}
                      {{old}}
      {% else %} {{new}}
      {% endif %}```
mighty ledge
#

well, you never cast old to a float

ivory delta
#

I just prefer pipes over functions.

#

Still the same filter, just a different style of writing it.

mighty ledge
#

still need to cast old to a int or float

#

which you aren't doing

floral shuttle
#

ok let me try that

mighty ledge
#

it'll never be none then

#

so you have to do it after the if old == None

floral shuttle
#

yes thats tricky, ran into trouble floating before, all templates remained 0 πŸ˜‰

mighty ledge
#

why aren't you just using filter?

silent barnBOT
floral shuttle
#

getting '>' not supported between instances of 'str' and 'float' if I use the |float on old... {% set old = states(entity_id) %} {% set new = value %} {% if old == None %} {{new}} {% elif old == 0 and new < 2 %} {{new}} {% elif new > old|float * 1.5 or (new < old and new != 0) %} {{old}} {% else %} {{new}} {% endif %}

mighty ledge
#

value is also a string

floral shuttle
#

filter: because a) that smoothes out the errors I like to ignore instead and b) needs yet another entity... Id hoped to do it all in the mqtt sensor config

mighty ledge
#

outlier dude

#

it does exactly what you're trying to do

floral shuttle
#

if I use new = value|round(2), would new still be a string?

mighty ledge
#

it should be a float at that point

#

you should really just use the outlier filter

#

or range

#

if those don't get you what you want, make a FR for a range calc that acts like outlier

#

outlier with a radius of 2 is very close to what you want but the band moves with the value.

floral shuttle
#

thanks, Ill have a go at that. Meanwhile I tried this in template editor {% set old = states(entity_id) %} {% set new = value|round(2) %} {% if old is not none %} {% if old == 0 and new < 2 %} {{new}} {% elif new > old * 1.5 or (new < old and new != 0) %} {{old}} {% else %} {{new}} {% endif %} {% else %} {{new}} {% endif %} which seems to behave well

#

but in the mqtt value_template it yields Unavailable....

#

ofc I replace the values in the opening set's with test values

#

like this {% set old = 0 %} {% set new = 1 %} {% if old is not none %} {% if old == 0 and new < 2 %} {{1}} {% elif new > old * 1.5 or (new < old and new != 0) %} {{2}} {% else %} {{3}} {% endif %} {% else %} {{4}} {% endif %}

mighty ledge
#

figure out which is causing the problem

#

new or old

#

by hardcoding new or old and keeping the other the value it's supposed to be

ivory delta
#

Or using outlier πŸ˜„

mighty ledge
#

no, that would be too easy

#

at this point, I'd want to figure out where the fuck up is in the template

floral shuttle
#

test for existence needs to be {% if states(entity_id) not in ['unknown','unavailable'] %}

#

at least that gets me past the initial test, and routes me to the correct endpoint in the template. Now I still need to test that with real life value, and see if an 'old' value is seen and compared to a new value, the actual latest mqtt value

#
      {% set new = value|round(2) %}
      {% if states(entity_id) in ['unknown','unavailable'] %} {{new}}
      {% else %}
        {% set old = states(entity_id)|float %}
        {% if old == 0.0 and new < 2 %} {{new}}
        {% elif new > old * 1.5 or
                     (new < old and new != 0) %}
                      {{old}}
        {% else %} {{new}}
        {% endif %}
      {% endif %}
#

maybe I need to use new != 0.0 in the elif, not sure yet...

#

for now, I see the Energy sensors update their value and get a value at reload, so those bits of the template fare well. must yet experience a downward dip, or reset to 0 to see if they survive ;-0

#

all in all I have capped my power sensors to the max rate limit of their documented range and guarded the energy sensors for these ridiculous spikes and dips. I feel the current 'dumb' energy integration really should be doing all of that, by implementing these heuristics.

tacit arch
#

if in configuration file I create a sensor, when I delete it from the file, it will survive? If I create another sensor with same id/name, will be a new sensor? I'm going banana

silent barnBOT
tacit arch
mighty ledge
ivory delta
#

Not so unique then πŸ˜‚

#

Generate UUID's for your unique ID's, then you don't have to remember which ones you've used before.

#

Never trust a human to come up with anything unique or random.

tacit arch
#

I supposed a unique id of an existing entity, if I delete the entity I delete the id no?
I should do it on the db?

mighty ledge
#

I don't know what you're asking. I can tell you, you should have 2 different unique_id's there. Not the same one.

tacit arch
mighty ledge
#

ah i didn't notice that, it looked the same at a glance

#

so you need to rephrase your question because I'm having a hard time understanding what you're asking

tacit arch
mighty ledge
#

you can delete it from the entities page

#

delete it, then restart

tacit arch
mighty ledge
#

screenshot?

mighty ledge
#

does the sensor say "read only" on the entities list page?

tacit arch
#

no, only "this entity is unavailable

mighty ledge
#

anyways, what you can do is rename the entity_id on that one (the one you can't delete), then find the new one that's being created and rename that to the old entity_id that you want.

#

AH, nevermind

#

i see your issue

tacit arch
#

ok, but usually how I delete all data associated to an entity?

mighty ledge
tacit arch
#

don't know, maybe are stored on db even if the entity have been deleted?

mighty ledge
#

no, you have a bad configuration, look at the arrows

tacit arch
mighty ledge
#

hahaha, we've all done it

tacit arch
#

thanks

mighty ledge
#

np

#

I spent 3 hours this morning

#

trying to find a bug in my code

#

and it was a spelling error. in the word actual. I spelled it actaul

#

so, definitely been there

tacit arch
#

ok, the entity now it's normal, I've to wait tomorrow to test if all works as I hope
thanks

fiery ledge
#

I have bit of a trouble with entities, they by default show as value based etc.. power meter and instead of text history I have value based one. Any idea how I can modify entity to correct this?

thorny snow
#

Hello! Anyone know how to call sqlite query from template?

ivory delta
#

You don't, templates don't make service calls.

#

You can possibly use templates with the SQL sensor though - the sensor makes the SQL call, the template would just describe what call to make.

mighty ledge
fiery ledge
mighty ledge
#

It has a unit of measurement

fiery ledge
#

It’s not explicitly configured, can I somehow enforce β€œnone” to fix this?

mighty ledge
#

You can customize it

#

But it’s probably worth it just making a template boolean because it’s not really a sensor

fiery ledge
#

Any idea how to customize it? To get rid of this unit thingy?

mighty ledge
#

.customize

shell pine
#

Hi, how can I get the sum of multiple entities' states in a template? without listing them one by one
the entites are in numerical order name_1, name_2, name_3 etc so is there a way I can match them by regex name_\d and then get the sum with like a .sum() operation?

inner mesa
#

{{ states|selectattr('entity_id', 'match', 'input_number..*temp')|map(attribute='state')|map('int')|list|sum }}

#

for instance

#

@shell pine

ivory delta
#

You'll want to escape the first period in that: 'input_number\..*temp

inner mesa
#

it works as-is

ivory delta
#

Although the first would work because . will match any character, including the period πŸ˜‚

inner mesa
#

yes

ivory delta
#

It's just somewhat redundant.

inner mesa
#

well, that's true. I could just leave it out entirely

#

I think I had the same discussion recently - getting a sense of deja vu

ivory delta
#

search is always from the start of the string, right? I think I prefer match, even when I might be after the first part of a string, just so I don't have to remember two different tests.

#

Oops, other way round.

inner mesa
#

anyway, I've contribute my required "interesting template of the day", so I guess it's time for a beer

#

could be trouble, considering that it's only 2:30pm and I'm in my second week of a new job

ivory delta
#

It's Friday afternoon, no-one expects you to do any work.

plucky heron
#

i have some fields defined in a script, but I don't see the fields UI when calling it from an automation\script

#

all i see is a data: field

plucky heron
#

whoops... didn't add a selector for the fields. it's working now

hexed badger
#
entity_id: counter.button3
value_template: xxx modulo 4 == 0 xxx``` Is there a way to test if counter.button3 % 4 == 0
fossil venture
#
platform: template
value_template: "{{ states('counter.button3')|int % 4 == 0 }}"
quick heath
#

My template won't round, what am I missing? {{ states('sensor.panel_total_kwh_cost') | float + 0.82 | round(2) }}

nocturne chasm
ivory delta
#

You're rounding the 0.82, not the result of the addition.

#

Order of operations.

quick heath
quick heath
inner mesa
#

Parentheses

#

{{ (states('sensor.panel_total_kwh_cost') | float + 0.82) | round(2) }}

ivory delta
#

Quick maffs

frank yacht
#

Hello All. I'm having trouble with a template for the Emulated Kasa integration. I'm getting the following config invalid message after I input a template for the dimmer:
light.bedroom_1_bedroom_main_lights (its second from bottom). Attached is a link to debian...https://paste.debian.net/1212261. Can anyone point me in the right direction on where I'm screwing up? Thank you.

#

Invalid config for [emulated_kasa]: expected float for dictionary value @ data['emulated_kasa']['entities']['light.bedroom_1_bedroom_main_lights']['power']. Got "{{ (state_attr(β€˜light.bedroom_1_bedroom_main_lights', 'brightness')|float/255|float)*72.0}}". (See /config/configuration.yaml, line 26).

mighty ledge
#

your single quotes should be '

#

not the fancy ones

frank yacht
mighty ledge
#

β€˜

frank yacht
#

should they be removed, or replaced with "

mighty ledge
#

read previous post

inner mesa
#

use normal quotes

inner mesa
#

not quite

#

now you're using the same quotes inside and outside

#

which will break the parser

frank yacht
#

so only have them on the outside?

inner mesa
#

as you can see from the color-coding in your link

#

also no

#

I'm not sure what you're doing there, but something like this:

#
light.bedroom_1_bedroom_main_lights:
      name: "Bedroom 1 Lights Current Consumption"
      power: "{{ (state_attr('light.bedroom_1_bedroom_main_lights', 'brightness')|float/255)*72.0}}"
frank yacht
#

You're the man. I appreciate all your help...not just now...be also in the past.

fresh vortex
#

I am trying to parse some nested JSON MQTT messages from a Tasmota sensor and nothing seems to work. Here is the message:

{"Time":"2021-09-18T11:43:28","MAX31865-0":{"Temperature":64.19,"Resistance":1069.72,"Error":0},"TempUnit":"F"}

I have tried:
value_template: "{{ value_json[['MAX31865-0'][0]['Temperature']] }}"

value_template: "{{ value_json.MAX31865-0.Temperature }}"

inner mesa
#

value_template: "{{ value_json['MAX31865-0'].Temperature }}"

fresh vortex
#

I'm getting a value of Unknown

inner mesa
#
{% set data = {"Time":"2021-09-18T11:43:28","MAX31865-0":{"Temperature":64.19,"Resistance":1069.72,"Error":0},"TempUnit":"F"} %}
{{ data['MAX31865-0'].Temperature }}
#

-> 64.19

fresh vortex
#
  • platform: mqtt
    name: "Wine Cellar Bottle Temperature"
    state_topic: "tele/wine_cellar_2/Sensor"
    unit_of_measurement: "Β°F"
    value_template: "{{ value_json['MAX31865-0'].Temperature }}"
mighty ledge
fresh vortex
#

I don't see any errors in the log. I see that it works in the template tool.

mighty ledge
#

has the sensor gotten a new value?

fresh vortex
#

I'm watching the sensor with MQTT.fx and its updating every 10 sec for debugging. I see an error:

Template variable warning: 'list object' has no attribute 'Temperature' when rendering ''

mighty ledge
#

ok, that's the error then

#

and the info you posted wasn't correct

fresh vortex
#

I don't understand what I posted wasn't correct. Is that a list of one item?

mighty ledge
#

Your json does not have a list, yet the error claims it is a list

fresh vortex
#

Tasmota supports (3) MAX81865 but there is only one connected.
I tried this with no change:
value_template: "{{ data['MAX31865-0'][0].Temperature }}"

inner mesa
#

well that won't work

#

data is just what I called the variable that I used for your data

fresh vortex
#

sorry I accidently pasted from the template tool

inner mesa
#
- service: persistent_notification.create
  data:
    message: "{{ value_json }}"
#

add that to your action to see what it's actually getting

fresh vortex
#

Pardon my noobiness but I am just defining sensors at this point. Can I add that to the sensor definition?

inner mesa
#

oh, sorry. then just use value_template: "{{ value_json }}"

fresh vortex
#

@inner mesa Thanks its working now.

#

thanks Petro

blissful copper
#

HI everybody. I'm just struggling with this single-line-templatecondition:
- condition: "{{ state_attr('cover.bedroomshutter', 'current_position') < 9 }}"

#

it's producing the following error:
ERROR:homeassistant.config:Invalid config for [automation]: Unexpected value for condition: '{{ state_attr('cover.bedroomshutter', 'current_position') < 9 }}'. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data['condition'][1]. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 58).

#

Funny thing: The same in the "classic-format" is working:
- condition: template value_template: > {{ state_attr('cover.bedroomshutter', 'current_position') < 9 }}

fresh vortex
#

How do I concatenate a character and MQTT value in YAML?
this is what I am trying to do:
unit_of_measurement: "Β°{{ value_json['MAX31865-0'].TempUnit }}"

inner mesa
#

that doesn't work?

fresh vortex
#

it returns:
64.19 Β°{{ value_json['MAX31865-0'].TempUnit }}

inner mesa
#

oh, you can't have a dynamic unit_of_measurement

fresh vortex
#

really?

#

I am still curious how I can combine the character and MQTT value together in YAML.

inner mesa
#

you can't generate a dynamic unit_of_measurement

#

what you're doing would probably work fine if you did it where it is allowed

fresh vortex
#

where is it allowed?

inner mesa
#

many places

#

in service:, in a data: block, or wherever the docs say it is

#

unit_of_measurement string (optional)
Defines the units of measurement of the sensor, if any.

#

"string"

#

compare and contrast with:

#

value_template template (optional)
Defines a template to extract the value. Available variables: entity_id. The entity_id can be used to reference the entity’s attributes.

#

"template"

fresh vortex
#

ok I have a lot of reading to do

fresh vortex
inner mesa
#

Your quotes in the condition are broken

#

First, you have two sets of quotes surrounding the template and second you need to mix the quotes inside and outside

fresh vortex
#

I tried using the visual editor and that what came out as YAML
like this?
value_template: "{{ trigger.payload == 'lockhouse' }}"

inner mesa
#

Yes

fresh vortex
#

it still wont trigger

inner mesa
fresh vortex
#

@inner mesa thank you

silent barnBOT
grand merlin
#

Hi! not sure that the right place for my post but I'm using node red for presence notificaiton (using this code)

https://hastebin.com/oxaruceqir.json

the screenshot attached to the notification don't work at all but that because of CloudFlare access I think...

anyway how can I add this to my template so when I click on the notification, I actually open another app (UniFi Protect)
actions:
https://hastebin.com/jiqukapuni.yaml

grand merlin
mighty ledge
hexed badger
#

I have a template condition like this: ```condition:

  • condition: template
    value_template: '{{ trigger.json.key == ''goodvalue'' }}'``` is it possible to access the secrets.yaml? I want to have ''goodvalue'' be "!secret api_key" as it can be done in configuration.yaml
inner mesa
#

that's your option

#

it seems pretty innocuous as hacks go...

willow belfry
#

Does anyone know whether Home Assistant publishes the total number of devices for a given integration as an entity? Or do I need to create a template for that?

#

Specifically, I'd like to keep track of the total number of Zwave devices in my network.

inner mesa
#

You would need a template. This is the one I use:

#
- platform: template
  sensors:
    zwave_status:
      value_template: "{{states|selectattr('entity_id', 'search', 'node_status')|selectattr('state', 'in', 'alive, asleep')|list|count}}/{{states|selectattr('entity_id', 'search', 'node_status')|list|count}}"
      friendly_name: ZWave Node Status
willow belfry
#

Am I crazy or is there no way to create Templates via the UI?

ivory delta
#

Templates aren't a standalone thing. You use them in other things.

#

You wouldn't 'create a template' in the UI.

#

What are you trying to do?

dreamy knot
#

Was just working on this actually. You can put a template in the markdown card in Lovelace.

willow belfry
ivory delta
#

What is it with everyone tagging on replies tonight?

silent barnBOT
#

@willow belfry When using Discord's Reply feature it defaults to pinging the person you reply to, which can get frustrating for the target. Click @ ON to @ OFF to stop this - on the right side of the compose bar.

You have to change this every time (thank the Discord devs for that).

ivory delta
#

If you want to add a template to an automation, there's nothing stopping you doing that. You can enter templates via the automations UI.

willow belfry
#

πŸ‘

floral shuttle
#

I seem to have to add the domain like selectattr('entity_id', 'match', 'switch.freezer*') to have it return those 2 switches. is that expected behavior?

ivory delta
#

Yes... match vs search.

floral shuttle
#

it gets even stranger, with selectattr('entity_id', 'match', 'switch.f*') it lists all switches... including many that dont use the 'f' at all

ivory delta
#

Yes... because that's what you told it to find.

#

If you're going to use RegEx, learn how to use RegEx

inner mesa
#

β€˜switch.f*’ matches switches that start with zero or more f characters

#

There’s general and understandable confusion between normal globbing and regex

floral shuttle
#

and why would selectattr('entity_id', 'search', '.fre*') result in ```[
"switch.freezer_bijkeuken",
"switch.freezer_garage",
"switch.front_room"
]

#

because the search is looking for 0 or more e'? in this case 0...

ivory delta
#

Because you're telling it to find 'any character, followed by f, followed by r, followed by e zero or more times'

#

Put your pattern into regex101 and it'll break it down for you.

floral shuttle
#

Ok, I see.

inner mesa
#

What you’re using * for requires β€˜.*’

ivory delta
#

The funny thing about solving a problem with RegEx is that you now have two problems.

#

Try this as your search term for me?
^(.+)+$

floral shuttle
ivory delta
#

Yes... you wrote it in that order.

floral shuttle
ivory delta
#

Seriously... if you want to use RegEx, learn RegEx. It's powerful but it's complicated... and there's no easy way to figure out what it does other than reading a proper guide.

#

You could give thousands of examples here and ask us what they do, and still be no better at it. You need to understand the syntax... which regex101 also teaches.

mighty ledge
#

It’s super complicated

#

Once you learn it tho

ivory delta
#

Once you know the syntax... it's easy to come up with patterns of your own.

mighty ledge
#

It’s great if you don’t care about Speed

ivory delta
#

There's this simple RegEx that tons of software uses:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

mighty ledge
#

Marius, it’s not something you’ll learn quick

floral shuttle
#

for my usage now, Ill use something like 'daystart' and its pretty unlikely it will find anything other than containing that phrase πŸ˜‰

ivory delta
#

Even as a somewhat-capable developer, it took a long time for RegEx to 'click' for me.

mighty ledge
#

Ya

#

Well, the prt that had to click was the reading the documentation and understanding it

ivory delta
#

Kinda happens in stages too:

  • learn to read basic patterns
  • learn to write basic patterns
  • learn when to use those patterns instead of other programmatic approaches
  • learn more complex patterns
  • repeat
mighty ledge
#

Those online testers are awesome for learning g it

ivory delta
#

Boss: are you playing games again?
Me: nope, practising my RegEx skills.

floral shuttle
#

i like/use it to auto create lists with entities, so I can use those in a group, by simply copying that, (since we can no longer do that in the dev states, because of the listed friendly names)

mighty ledge
#

Tbh tho, I’ll still just Google crap that other people do then add/remove what I need

ivory delta
#

This is the way.

floral shuttle
#

may I ask a final one before I go retreat an study all that... 'freez*power' in dev states returns all entities I need, but no matter what I try in the regex template, it returns an empty list..

inner mesa
#

again, "*" represents 0 or more of the previous character. Is that what you want?

#

0 or more z characters, in that case

ivory delta
#

And I'll repeat... use regex101 to figure it out.

#

Get your pattern right before you try applying it somewhere.

floral shuttle
ivory delta
#

Rob told you what to change.

#

.* means 'any character zero or more times`.

floral shuttle
#

'sensor.freez.*power' !, or even 'freez.*power'

#

yes, thank you!

ivory delta
#

And you'd know what to do if you bothered reading the guidance on regex101 and used it as a playground to test your pattern against potential matches.

floral shuttle
#

I will, believe me. For now, I have found the replacement for my much desired 'contains' filter!

mint crane
#

hello, has anyone got an example of a time arithmetic template? I'm looking to find the hours and minutes from current time to 12:30am.

#

so far i've got two lines, but I dont think they're compatible in this form

{{ as_timestamp(strptime("12:30", "%I:%M")) }}```
inner mesa
#

kinda a pain the ass because it cross the date boundary

#

either it will, or it won't, so you need to be careful

mint crane
#

I could quite happily get whatever value it is to midnight and then add 30 mins

inner mesa
#

and if it's between midnight and 12:30...

mint crane
#

then, i'll be in bed and wont look πŸ™‚

inner mesa
#

{{ now().replace(hour=23, minute=59, second=59) - now() }}

mint crane
#

it's for a quick reference on a dashboard so i can set the dishwasher delay to be in the cheap energy window, which starts at 12:30am

inner mesa
#

I hate this, but it works:

#
{% set delta = now().replace(hour=23, minute=59, second=59) - now() %}
{% set hours = (delta.total_seconds()/3600)|float %}
{% set minutes = (hours % 1) * 60 %}
{{ hours|int ~ ":" ~ minutes|int }}
mint crane
#

thank you! why the hate?

#

just a bit clunky?

inner mesa
#

yes. I was hoping that I could just do delta.hour and delta.minute

#

as you can with a datetime, but can't with a timedelta

#

I hate this ever so slightly less:

#
  {% set delta = ((now().replace(hour=23, minute=59, second=59) - now())|string).split(":") %}
  {{ delta[0] ~ ":" ~ delta[1] }}
inner mesa
#

I don't see how

mint crane
#

ok, i just thought it might be related πŸ€·β€β™‚οΈ

inner mesa
#
{% set delta = (((now().replace(hour=0, minute=30, second=0) + timedelta(days=1 if not (0 <= now().hour < 1 and now().minute < 30) else 0)) - now())|string).split(':') %}
{{ delta[0] ~ ":" ~ delta[1] }}
#

that takes care of the day split

mint crane
#

very good work! thank you!

inner mesa
#
{% set delta = ((now().replace(hour=0, minute=30, second=0) + timedelta(days=1 if now().strftime('%H:%M') > '00:30' else 0) - now())|string).split(':') %}
{{ "%s:%s"|format(delta[0], delta[1]) }}
#

not sure if it's getting better, or just different

ivory delta
#

This isn't even its final form.

inner mesa
#
{% set delta = ((now().replace(hour=0, minute=30, second=0) + timedelta(days=(now().strftime('%H:%M') <= '00:30')|int) - now())|string).split(':') %}
{{ "%s:%s"|format(delta[0], delta[1]) }}
#

too many parentheses

deep shoal
#

Hi!

#

I am just starting to explore templating in more detaild and had a syntax question for the folks here.

#

I have multiple template sensor lines in my config.yaml, and I am not sure if that is the most efficient way to write it.

#

The code is working.

#
  • platform: template
    sensors:
    left_garage_status:
    • platform: template
      sensors:
      car_status:
#

The question is whether I include only one -platform: template and then nest the sensurs under that. Or perhaps one -platform: template and sensors, and then nest everything under that.

inner mesa
#

It doesn’t matter

deep shoal
#

If you wanted to simplify how would you?

#

Okay, meaning could I have one template and one sensor and nest everything under it?

#

Thank you!

#

e.g.:

  • platform: template
    sensors:
    sensor#1 YAML.....
    sensor#2 YAML.....
inner mesa
#

it really doesn't matter

#

I have both

deep shoal
#

Okay, thank you.

tribal pelican
#

Good morning i use the platform teleinfo and i would like to perform some calculations with the input data i did setup the lambda like this but β€œunavailable” is not recognized somebody-may help me?

#
  • platform: template
    name: "Conso du jour HC Blue"
    id: today_hc_blue_consumption
    unit_of_measurement: "Wh"
    icon: mdi:moon-waning-crescent
    update_interval: 3600s
    lambda: !lambda |-
    if (id(edf_hcjb), unavailable) {unavailable;} else {return ( (id(edf_hcjb).state-id(yesterday_hc_blue_consumption).state) / 1000);}
fossil venture
silent barnBOT
tribal pelican
#

Yes Esphome

fossil venture
earnest cosmos
#

I want to trigger a script only if two conditions are met. Something seems to be troubleseome here

script:
...
  sequence:                       
    - service: >
        {% if is_state('binary_sensor.dark_inside', 'on') and is_state('light.lys_grunnbelysning', 'off') %}
        script.lys_grunnbelysning_on
        {% endif %}
marble jackal
#

Put it in a condtion instead of a service call

#

You will end up with an empty service call this way, if the conditions are not met, and that will give errors

earnest cosmos
#

I need to continue after this πŸ™‚

marble jackal
#

then use a choose:

earnest cosmos
#

Ah!
So if these two conditions ar met as one choose: statemennt and tha last (now a condition) as the second choose: , then?

charred dagger
#
- do something
- choose:
  - conditions: "{{ is_state() and is_state() }}"
    sequence:
      - call service
- do something else```
marble jackal
#
  sequence:
    - choose:
        - conditions: "{{ is_state('binary_sensor.dark_inside', 'on') and is_state('light.lys_grunnbelysning', 'off') }}"
          sequence:
            - service: script.lys_grunnebelysning_on
    - service: whatever
``` but thomas was faster
earnest cosmos
#

Thank you, @charred dagger πŸ™‚

#

Ha, ha.. What a race!!!

charred dagger
#

but thomas was faster
I cheated

earnest cosmos
#

and thank you @marble jackal

#

Would end up like this, then ?

script:
  someone_coming_home:
    alias: '[House] - Someone coming home'
    sequence: 
      - choose:
        - conditions: "{{ is_state('binary_sensor.dark_inside', 'on') and is_state('light.lys_grunnbelysning', 'off') }}"
          sequence:
            - service: script.lys_grunnebelysning_on
      - condition: template      ## Continue only if one adult came home
        value_template: "{{ is_state('person.pal', 'home') or is_state('person.eva', 'home') }}"
      - service: script.adults_coming_home
fossil venture
#

Hassbot does not like it but I can't see anything wrong with it.

charred dagger
#

Hassbot never liked comments, I think. ```yaml

Perfectly valid yaml

a:

  • 1
  • 2
#

Or maybe it does.

rugged laurel
#

What we see now is valid, what @silent barn reacted to was not, the post was edited.

charred dagger
#

Right. Good eye.

ionic briar
#

Trying to setup a quick light automation ahead of traveling to simulate presence. Was thinking of using the On_off schedule template but it needs a specific time, I'd like to specify "sunset" as the ON trigger and a specific time for the OFF. I assume this can be done in the YAML, can I use the sun.sun next_dusk: '2021-09-21T17:44:06.631221+00:00' attribute somehow?

nocturne chasm
#

{{ state_attr('sun.sun', 'next_dawn') }}

#

Depending on what you want to do.

ivory delta
marsh yoke
#

im trying to implement a delay based on an input_number (in minutes) {{ states("input_number.minutes") | int }} the value is 35 delay: '{{ states("input_number.minutes") | multiply(60) | int }}' gives me 2100 - what is the coreect template i would beed to set the delay for minutes? multiply(1000) | multiply(60) correct?

fossil venture
#

{{ states("input_number.minutes") | int * 60 }}

marsh yoke
#

thanks

ionic briar
odd flare
#

is this the correct format for an if statement to convert 1 and 2 to Source A and B? value_template: >- {% if is_state( (value | int) , '1') %} Source A {% else %} Source B {% endif %}

inner mesa
#

not like that - you're using value where an entity_id should be, converting the value to an int and then comparing with a string

#

it can be done more compactly like this:

#

value_template: "{{ 'Source A' if value == '1' else 'Source B' }}"

#

without knowing where value is coming from or what it's type is, of course

odd flare
inner mesa
#

it's still unclear what type value will be

#

but you can try that, or use value_template: "{{ 'Source A' if value == 1 else 'Source B' }}" if it comes in as an int

odd flare
#

It will return an integer thats 1 or 2

#

INTEGER {sourceA(1),sourceB(2)}

inner mesa
#

ok. you have some examples

odd flare
#

i can use snmpget to sample the comms

#

iso.3.6.1.4.1.318.1.1.8.5.1.2.0 = INTEGER: 1

inner mesa
#

it's not that complicated

#

does it work?

odd flare
#

going to try it now

odd flare
mighty ridge
#

Hi all. Is it possible to manually fire off an event? Specifically, entering a zone? I want to test my templating for when someone enters the zone then it will pass trigger.id to condition and I want the condition to verify certain things for each user. I've tried changing the person's state from not_home to home or to the name of one of the zones, but no luck.

inner mesa
#

you can definitely do that from devtools -> States

#

"entering a zone" is no different from the state of a device_tracker changing to the name of a zone

mighty ridge
#

Ok so to expand on that, what is the state it should be in?

mighty ledge
#

what trigger are you using?

mighty ridge
#

Oh, wait, the state should just be the zone, right?

#

State: wba

#

or state: burns

#

right?

mighty ledge
#

if you're just changing the device_tracker yes

mighty ridge
#

person.myname

mighty ledge
#

but that depends on what trigger you're using for the zone triggering

mighty ridge
#

Enters zone

mighty ledge
#

please post it

mighty ridge
#

hmm it wont let me upload as a file, I'll try pastebin or is a screen shot ok?

#

Can see if that works

mighty ledge
#

well, your syntax is wrong for sure

#
{% if trigger.id == 'triggerjimbob' %}
#

but, to test those zone triggers, you need to force the state change on person

#

so set the device_tracker state to equal the zone friendly name

#

and that should propagate to your person

#

is_state( only gets an entities state. Trigger is not an entity

mortal ruin
#

I'm getting repeat errors, that I don't understand. Does this mean the sensor doesn't have a state defined?

#

How do I do formatting again?

mighty ledge
#

3 backticks

mortal ruin
#
 Logger: homeassistant.helpers.template
Source: helpers/template.py:1496
First occurred: September 20, 2021, 1:50:58 PM (2591 occurrences)
Last logged: 9:00:02 AM

Template variable error: 'state' is undefined when rendering '{{ state('sensor.power_home_123_1d')|float}}'
mighty ledge
#

it's states() not state()

mortal ruin
#

haha

#

thank you

#

the 3 backslashes didn't seem to work

mighty ledge
#

backtick is not backslash

#

`

#

back tick

#

\

#

back slash

mortal ruin
#

Thank you!

mighty ledge
#

np

mortal ruin
#

So I just need to change it to states?

#
    - name: "Total Power Usage"
      state_class: total_increasing
      unit_of_measurement: kWh
      device_class: energy
      state: >
        {{ state('sensor.power_home_123_1d')|float}}
mighty ledge
#

yep

mortal ruin
#

Awesome

mighty ledge
#

although, what you're doing is pointless

mortal ruin
#

Why is that?

mighty ledge
#

because you aren't performing math on the state, so all you're doing is replicating the state into another entity

#

if you need to add or change attributes to your existing entity, use customization

mortal ruin
#

Oh, I think I was doing that while my source entity wasn't updated to a total increasing yet.

#

but I think the latest update fixed that.

#

I'll delete the sensor. Thanks for the reminder.

#

Anyone have experience creating something to display power usage of something outside of the energy dashboard?

#

I want to see if it's worth running my miner based on power usage or not.

#

So I think I need to create two sensors then a third one to do the math for the total

#

one for off peak and one for peak

#

I said power usage, but I meant power cost.

mortal ruin
#

I guess the part I don't understand is if it will store the data correctly

thorny snow
#

Hello there,

I have these two sensors where in the templates tab it shows them as I wish, that is, one per line.

If, however, later when I create the entity card it shows it to me immediately, do you know why it can be?

mortal heart
#

Hello all, its been a few years since ive been in the HA stuff.. had a good amount of stuff configured back in 18, then deployed, came home and my box was dead, and no backups, and decided just to go Hubitat, but now ive decided to come back.. anyhow I cant remember for the life of me how to create a binary sensor from my locks. Example I just want an entity card to show lock status but not interactive.

    sensors:
       front_door_status:
        friendly_name: Front Door
        icon_template: >
          {% if is_state('lock.front_door','locked') %} mdi:door 
          {% else %} mdi:door-open
          {% endif %}```
thorny snow
#

`{{ (states('sensor.unauto')) }}

{{ 'Linea' + ((states('sensor.unauto')).split('LΓ­nea')[1]) + 'Linea' + ((states('sensor.unauto')).split('LΓ­nea')[2]) }}`

#

and output is:

#

LΓ­nea L92 4 minutos
LΓ­nea L91 8 minutos
LΓ­nea L92 17 minutos
LΓ­nea L62 19 minutos
LΓ­nea L91 23 minutos
LΓ­nea L62 39 minutos
LΓ­nea L92 54 minutos

Linea L92 4 minutos
Linea L91 8 minutos

#

but the sensor then shows it to me in a row, without a line break

Line L92 3 minutes Line L91 6 minutes

#

How are the images inserted in discord?

mighty ledge
#

imgur

thorny snow
mighty ledge
#

whitespace carrage returns are removed from states

#

if you want to display that, use markdown card

thorny snow
#

ok, i will try it

mighty ledge
thorny snow
mortal heart
mighty ledge
mortal heart
#

oh yea I think i got that , I have to go digging to remember whereei put in my yamls..lol its been a while. but ill get it all sorted.

#
   sensors:
      front_door_status:
       friendly_name: Front Door
       value_template: >
         {% if is_state('front_door_lock','on') %}  ```
#

I was doing this on a blank Viscual code from as much memory as I could .

#

though these days the memory is shot

mortal heart
#

got it πŸ™‚

inner mesa
#

πŸ‘ There are a few things broken in there..

tribal fossil
#

Anyone have a pointer as to why I'm getting TypeError: first argument must be string or compiled pattern when doing something like {% set inputs = states.input_boolean %} {% if inputs | list | count > 0 %} {{ inputs | map(attribute='entity_id')|join(',')}} {% endif %}

ivory delta
#

What does inputs evaluate to on the third line?

tribal fossil
#

It should be the DomainStates for inputs_boolean, no?

#

As I'm uidnerstanding the templates, I saying give me all input_booleans as inputs. If there are more than 0 then map the entity_ids and join them with ,

#

The actual logic will be filtering down the input_booleans, but I was just trying super basic for testing.

ivory delta
#

I'm not asking what you think it does. I'm asking you what it actually does.

#

Find out what the output of inputs is on the third line.

worthy venture
#

my automation aint working... the trace shows Error: In 'template' condition: AttributeError: 'mappingproxy' object has no attribute 'lower' however i don't see where i call "lower":

  - condition: template
    value_template: >-
      {{ is_state_attr(trigger.event.data.new_state.attributes, "icon",
      "mdi:memory") }}```
#

for reference

  - platform: event
    event_type: state_changed
    event_data:
      entity_id: sensor.memory_use_percent
inner mesa
#

The first argument to is_state_attr is an entity_id

worthy venture
#

oh, ok so i should just access trigger.event.data.new_state.attributes directly?

tribal fossil
inner mesa
#

if your goal is to get the icon attribute, then trigger.event.data.new_state.attributes.icon

worthy venture
#

ok, and i guess i need to guard against new_state then being None

inner mesa
#

if you want to do the same test, then just use trigger.event.data.entity_id as the first parameter

tribal fossil
#

So everything seems like it should be fine. It's just....not when it's inside of the if. Outside it seems to work just fine. πŸ€”

inner mesa
#

add |list to something that returns a generator to see the elements

worthy venture
#

right but that would always be the new state, so i cant do that if i want to reference the old state?

inner mesa
#

that's just old_state

#

refer to what you want

worthy venture
#

so how would i do that with trigger.event.data.entity_id and is_state_attr?

inner mesa
#

that all seems overly complicated. why can't you just use a state trigger?

worthy venture
#

i was under the impression it wouldn't fire when only attributes change?

inner mesa
#

incorrect

worthy venture
#

ok, i was mislead by the docs then

inner mesa
#

it says it does in like the first paragraph of the docs

worthy venture
#

ah, misread that sentence

inner mesa
#

If only entity_id is given, the trigger will fire for all state changes, even if only state attributes change.****

worthy venture
#

right, i misread it as it wouldn't do it if only attribs change, silly brain

inner mesa
#

np, it's not intuitive

worthy venture
#

well, it certainly could do with a lot more consolidation of the docs and a lot more relevant examples

#

open source, so yeah i know πŸ™‚

#

that said, i must admit the new automation ui has improved massively since last time i fooled around, which is great

pseudo plume
#

hi, I am trying to integrate a switch, and I think what I need is to make a template

#

the device has a URL to switch on, another to switch off, and a third URL to get the state, which retirns a small piece of html

#

I took a look at REST, but it seems to be all based on json

#

I just need a few pointers to get started

#

also, each board can have up to 6 switches, but I just want to get 1 working to start

#

maybe I dont even need a template I am not sure

#

the only variable really is the IP address, and the button number

#

there are other URLs for setting a timer and so on but I can add those in later

worthy venture
#

@inner mesa ok, that seems to work, cheers!

pseudo plume
#

ideally I would jst enter the IP address and the automation would figure out the number of buttons

#

it also supports MQTT, so if that would be a better option, I could use that, though it seems a bit more complicated to get started with, but in future it might be the way to go

#

to set the state it is something like sending PUT to http://ip_address/avtion/button=1&state=1|0

#

1 or 0

#

and to read the state, something like send a GET to http://ip_addr/read?button=1

#

that would be enough to get me started

#

just not sure how to write that in a template

inner mesa
#

you don't use a template

pseudo plume
#

ah OK

inner mesa
#

templates don't do anything - they manipulate data that already exists in the HA state machien

pseudo plume
#

I see, so what would I use instead ?

inner mesa
#

using curl

pseudo plume
#

that's a template though

#

you just said I shouldnt use templates

inner mesa
#

it is not

#

how is it a template?

#

the only mention of a template is interpreting the output of the status call

pseudo plume
#

well OK, its a config script

inner mesa
#

templates aren't just "virtual things of any sort" - it's a technical term for Jinja

#

it's not a script either

pseudo plume
#

but I dont want to have to edit the config file each time I add a new switch

inner mesa
#

that's your option

pseudo plume
#

I just want to put in the ip address and give it a name

inner mesa
#

there's no such thing

#

you have to configure it like that

pseudo plume
#

eh ?

#

cant I add something like a switch class ?

#

seems a very awkward way of doing things

inner mesa
#

there's no place in the UI to just put an IP address and have it behave you've described

#

what you're doing is a very custom thing

pseudo plume
#

well to me it would make sense

inner mesa
#

normally, there would be an integration that would do the work and expose the switch

pseudo plume
#

make a switch template with name and ip address as variables

inner mesa
#

that's just not the way HA works

pseudo plume
#

have it show a UI where I can ipnuyt those values, and then the template would add it to the config

inner mesa
#

you can create a command line switch, as I linked

pseudo plume
#

I mean that is how I would do it

inner mesa
#

an integration could certainly be written to do exactly that, it just doesn't exist

#

that I'm aware of, at least. it's not a native thing

pseudo plume
#

well yes I am hoping to make a HACS integration from this

inner mesa
#

it would be fairly easy to do that

pseudo plume
#

OK, I mean right now Iam just testing...proof of concept if you like

pseudo plume
#

thanks...just getting started with this, its a bit hard to know where to start

#

so thanks for that

inner mesa
pseudo plume
#

thanks a lot !

#

so for now I should just start with edit the config and put in the command line bits right ?

#

I thenk that will add the device automatically ?

#

after a restart ?

inner mesa
#

~check first

silent barnBOT
#

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

inner mesa
#

but yes, it will create a switch entity

pseudo plume
#

OK, and then - sorry if it is abit off topic, but there was no example there to read a state back in teh commandline docs

#

ahh no

#

it has a check, value == 1

#

so what I need is actually something like a grep

inner mesa
#

that's what the state command line is for and the value_template

#

a template can do a regex search

pseudo plume
#

dearch_String ?

#

search_string ?

pseudo plume
#

so it is a template !!

#

lol

inner mesa
#

search and match

#

a tiny bit of it, yes

pseudo plume
#

I wasnt entirely off topic then

#

OK I ll try and figure it out from here

inner mesa
#

and even that part is optional πŸ™‚

pseudo plume
#

πŸ‘

pseudo plume
# silent barn

that isn't necessary any more, in the GUI, you can just go to Configuration / Server Controls and click on Check Configuration

inner mesa
#

that is incorrect

pseudo plume
#

which just told me I shouldn't use Tabs in scripts

inner mesa
#

that's why the first sentence is this:

#

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

pseudo plume
#

ah I see

#

sorry my eyesight isnt what it used to be

#

too many hours of staring at hi resolution monitros I guess

#

my typing skills are also on the decline....as you can see

#

shoddy keyboards are partly to blame for that, hard to find a decent one these days

pseudo plume
#

yikes ! config check is failing

#

it's looking for /root/.homeassistant

#

which is non existent

#

the instructions are totally cryptic "If your container name is something other than homeassistant, change that part in the examples below."

#

I have no idea what the container name is, or even if it is running in a container

#

it says in Info "docker: true" so I guess it must be, no idea whatthe name is though

ivory delta
#

If you're using Docker, you named the container. Unless you're using something shitty like Portainer to do it for you.

pseudo plume
#

Im using odroid