Template warning: 'int' got invalid input

Hi , i keep getting this warning in my log (it’s not the i didn’t bother, or wanted to see what’s happening after 2022.1) i am on latest-N greatest, just been Lazy lately. … and it’s still running

Template warning: 'int' got invalid input 'unknown' when rendering template '{% set s = states('sensor.rt_ax68u_d680_uptime') | int %}{{ '%02d:%02d:%02d' % ((s/86400)|int,((s%86400) / 3600)|int,(s%3600) / 60) }}' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1

here is the custom:template-entity-row.

  - type: custom:template-entity-row
    name: Router Uptime
    active: true
    icon: mdi:router-network
    state: >
      {% set s = states('sensor.rt_ax68u_d680_uptime') | int %}{{
      '%02d:%02d:%02d' % ((s/86400)|int,((s%86400) / 3600)|int,(s%3600) / 60) }}

It’s still running, but i don’t know how/what i should write it instead … i just wanted it to show days/hours/minutes … if anyone can solve the mystery, or even give me hint how i can make it better, like txt above or so, i would appreciate it … it is a littler tricky to “combine” a custom:template-entity-row , what i have tried(doesn’t “fit” into custom:multiple-entity-row i.e

con_dev

PS: i just noticed the “seamlessly syntax error” …the extra ( in-front of days | hours … just tried to remove them or/and add behind, several places … guess i just kept it like this, after i got it running :slight_smile:

Change all instances of int to int(0) in order to provide a default value of 0 in case the filter cannot convert the supplied value. It doesn’t have to be 0 and you can specify whatever default value you want.

The root problem is that the value of sensor.rt_ax68u_d680_uptime was unknown. The int filter cannot convert that to an integer so it reports a default value (which you must specify).

6 Likes

Done, and restarted, just in case, still showing/counting … but now multiple warnings, got even more ! … hmm

weird is, it’s trowing more now! , but still "see it as int, and not int(0), or int(3)

Template warning: 'int' got invalid input 'unknown' when rendering template '{% set s = states('sensor.rt_ax68u_d680_uptime') | int %}{{ '%02d:%02d:%02d' % ((s/86400)|int(0),((s%86400) / 3600)|int(0),(s%3600) / 60) }}' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1
18:28:14 – (WARNING) helpers/template.py - message first occurred at 18:28:14 and shows up 14 times 

clear your browser cache. When dealing with frontend templates, you only need to refresh your page and clear your cache. You don’t need to restart.

ok, i did try that first time, both clear cache and restart(not reboot) , but initially without anything after int, it’s throws less, if i put int(3) it throws same warning 18 times … in any case, it’s only during a restart it’s throwing this “warning” … and as i said above, im on latest and greatest … so the warning that it wont “render” after 2022.1 don’t seems to apply either … maybe ive done/missed some other things in my syntax, but i’ve tried alot, removing spaces, brackets etc …

Version core-2022.2.7
Installation Type Home Assistant OS
  - type: custom:template-entity-row
    name: Router Uptime
    active: true
    icon: mdi:router-network
    state: >
      {% set s = states('sensor.rt_ax68u_d680_uptime')| int(3) %}{{
      '%02d:%02d:%02d' % ((s/86400)|int(3),((s%86400) / 3600)|int(3),(s%3600) /
      60) }}

Template warning: ‘int’ got invalid input ‘unknown’ when rendering template ‘{% set s = states(‘sensor.rt_ax68u_d680_uptime’) | int %}{{ ‘%02d:%02d:%02d’ % ((s/86400)| int(0),((s%86400) / 3600)|int(0),(s%3600) / 60) }}’ but no default was specified. Currently ‘int’ will return ‘0’, however this template will fail to render in Home Assistant core 2022.1
18:36:44 – (WARNING) helpers/template.py - message first occurred at 18:36:44 and shows up 18 times

2022-02-16 18:36:44 WARNING (MainThread) [homeassistant.helpers.template] Template warning: ‘int’ got invalid input ‘unknown’ when rendering template ‘{% set s = states(‘sensor.rt_ax68u_d680_uptime’)| int %}{{ ‘%02d:%02d:%02d’ % ((s/86400)|int(3),((s%86400) / 3600)|int,(s%3600) / 60) }}’ but no default was specified. Currently ‘int’ will return ‘0’, however this template will fail to render in Home Assistant core 2022.1

2022-02-16 18:36:44 WARNING (MainThread) [homeassistant.helpers.template] Template warning: ‘int’ got invalid input ‘unknown’ when rendering template ‘{% set s = states(‘sensor.rt_ax68u_d680_uptime’)| int %}{{ ‘%02d:%02d:%02d’ % ((s/86400)|int(3),((s%86400) / 3600)|int(3),(s%3600) / 60) }}’ but no default was specified. Currently ‘int’ will return ‘0’, however this template will fail to render in Home Assistant core 2022.1

See my “root problem” explanation above. Which integration is used for sensor.rt_ax68u_d680_uptime? Whatever it is, it’s not supplying the sensor with a value at startup (at least not soon enough anyway).

FWIW, the last warning message you posted doesn’t contain int with a default value. Whatever changes you’re making don’t appear to “stick”.

HMM it seems like it’s the first " int " it wont “deal” with …
{% set s = states(‘sensor.rt_ax68u_d680_uptime’) | int %}

Integration = UPnP/IGD … and yes i’ve also noticed it’s the first int it wont accept, spite iv’e change several times now

Have you used this template in the template editor?

It seems you get errors from what is in the template editor from a few versions ago.

No errors…

That is not what I meant.

If you have a template in template editor that uses int or as_timestamp or any of those functions that need a default value, then there won’t be an error in template editor, but in the logs you get an error that you used a “incorrect” template in templates tool.

I get an error for something that I have not used in a long time.
Probably it’s on some device since each device has their own template editor.

2 Likes

ok, i got what you mean … i just did try to remove/reverse back to my initial template … int … without (0) … then it complains about a missing…end bracket )
… but i have no clue where i should put that, or whether where i might have 1 start
… i did wonder over the 2 “start” bracket before days | hours … as they dont seems to have an "end ) "

which devices are you referring to here ?, my “work environment” or the “entity” devices ?

… and yes i do recall that i did it in the template-editor, , so almost 53days ago

I meant some computer/mobile.
If I add a template on one computer, it will not be visible on the other computer even with the same account. I believe I have once tested a template and it’s still “open” somewhere.

1 Like

Thanks Guys, wont tag you :slight_smile: … syntax fixed by 123, petro and in specific Hellis81 did get me thinking … i disconnected my(this) work-laptop(where i did all the mess), then checked on the server ( error messages there in logs(obviously)) … but after restart (under server-controls) on the server, i got “clean” start-up log …
… so i only sitting here with my thoughts , should i restart this (work-laptop) obviously i didn’t help clearing browser, or will i as Hellis have to live with this, error/warning in the logs, when restarting from this laptop ? … i guess time will tell … so far i consider this as solved, thx again

1 Like

thou i see my (this) template on all 3 laptops, and a PC and phone, just by refreshing browser ( thou this time i hadn’t touched the server during these “changes”
PS … don’t ask me why all “commends” is tagged as “solution” … there is alot i don’t understand, but i did learn some more today … thou i did thought it was only the “view” design setup, that wouldn’t change, if i didn’t do a refresh on other devices,
… i use UI to initially create my “views” so they are ui-controlled, not YAML

That is not how it is for me.
I have different “views” on all devices.

ok, yes i’ve noticed that i can choose “default views” for different devices, but i try to keep my “responsive”, and so far, i don’t have any “Wall Dashboards” or any ipad etc, that would benefit from a Specific “View” … only been around here since October 21