Convert "input_number" to a "template light"

i think i can use something like this to translate :

"{{ (brightness / 255 * 90)|int / 90 }}"

Yes that would work, but it needs to be built into your shell command because you can’t pass information to your shell command.

set_level: is what gets called when you move the slider for the light. It will be the brightness slider when you enter the light control.

Typically, this would be a script where you could pass the brightness into the script, perform math, and set the hardware.

level_template: is where you pull the brightness level from the other slider.

aha, interesting
so actually i need a new shell command for this template light

so for example

  set_level:
    service: shell_command.dimmer1-1

shell: command:
dimmer1-1: "curl -k http://ip.php?hex={{ (brightness / 255 * 90)|int / 90 }}" 

something like that ?
is that a correct code?

Yeah that should work, but you won’t be able to use the slider to control the level. Every time you use the slider it will pull from your other slider. Is that what you want?

well, not a big deal
not gonna use the slider component anymore then :slight_smile: if i got this working though
just one quetsion, is this correct? if i do 255/ 90 *90 … , i get values with a comma, like for example 68,55

but i am only allowed to send 2 decimals to my ip controller, nothing behind the comma, so i need to send 68 , instead of 68,55

so my shell looks like this : is that correct?
why is there at the end of the line also int/90 ?

dimmer1-1: "curl -k http://ip.php?hex={{ '%02d'|format(states('light.dimmer1.brightness' / 255 * 90)|int / 90) }}"""

hmm, gives me an error when i launch the script

TypeError: unsupported operand type(s) for /: ‘str’ and ‘int’

ok, its more like this , but still an error , i dont need the int / 90 , because it needs to be a value between 0 and 90

dimmer1-1: “curl -k http://ip.php?hex={{ ‘%02d’|format(states(‘light.dimmer1.brightness’ / 255 * 90)|int) }}”""

ok, this works, gives no error, but also doesnt do anything on my light :slight_smile:

{{ '%02d'|format(states('light.dimmer1.brightness')|int / 255 * 90) }}"

I don’t think you can use shell command and remove the other slider. You need to:

  1. Make the other slider 0 to 255.
  2. Make your shell command work off the slider.
  3. Make your light template use everything properly.
    • Turn on needs to adjust slider and call shell command
    • Turn off needs to adjust slider and call shell command
    • set level needs to adjust the slider and call the shell command.
    • value_template needs to read the slider and determine weather the light is on or off based on the slider’s level.
    • level_template needs to read the slider level and use it as the brightness level.
shell_command:
  dimmer1: "curl -k http://ip.php?hex={{ '%02.f'%((states('input_number.dimmer1') | float / 255 ) * 90) }}"  

input_number:
  dimmer1:
    name: Eethoek Raam
    initial: 0
    min: 0
    max: 255
    step: 1

light template

light:
  - platform: template
    lights:
      dimmer1:
        friendly_name: "Eethoek Raam"
        value_template: "{{ states('input_number.dimmer1') | int >= 1 }}"
        level_template: "{{ states('input_number.dimmer1') | int }}"
        turn_on:
          - service: input_number.set_value
            data:
              entity_id: input_number.dimmer1
              value: 255
          - service: shell_command.dimmer1
        turn_off:
          - service: input_number.set_value
            data:
              entity_id: input_number.dimmer1
              value: 0
          - service: shell_command.dimmer1
        set_level:
          - service: input_number.set_value
            data_template:
              entity_id: input_number.dimmer1
              value: "{{ brightness }}"
          - service: shell_command.dimmer1

Ok, thnx in advance, gonna try it

But most important, will my shell command always send a value between 00 and 90 ?
And not like 00,00 and 90,99 ?

Yeah, this is the map of the equation:

0=00 
1=00 
2=01 
3=01 
4=01 
5=02 
6=02 
7=02 
8=03 
9=03 
10=04 
11=04 
12=04 
13=05 
14=05 
15=05 
16=06 
17=06 
18=06 
19=07 
20=07 
21=07 
22=08 
23=08 
24=08 
25=09 
26=09 
27=10 
28=10 
29=10 
30=11 
31=11 
32=11 
33=12 
34=12 
35=12 
36=13 
37=13 
38=13 
39=14 
40=14 
41=14 
42=15 
43=15 
44=16 
45=16 
46=16 
47=17 
48=17 
49=17 
50=18 
51=18 
52=18 
53=19 
54=19 
55=19 
56=20 
57=20 
58=20 
59=21 
60=21 
61=22 
62=22 
63=22 
64=23 
65=23 
66=23 
67=24 
68=24 
69=24 
70=25 
71=25 
72=25 
73=26 
74=26 
75=26 
76=27 
77=27 
78=28 
79=28 
80=28 
81=29 
82=29 
83=29 
84=30 
85=30 
86=30 
87=31 
88=31 
89=31 
90=32 
91=32 
92=32 
93=33 
94=33 
95=34 
96=34 
97=34 
98=35 
99=35 
100=35 
101=36 
102=36 
103=36 
104=37 
105=37 
106=37 
107=38 
108=38 
109=38 
110=39 
111=39 
112=40 
113=40 
114=40 
115=41 
116=41 
117=41 
118=42 
119=42 
120=42 
121=43 
122=43 
123=43 
124=44 
125=44 
126=44 
127=45 
128=45 
129=46 
130=46 
131=46 
132=47 
133=47 
134=47 
135=48 
136=48 
137=48 
138=49 
139=49 
140=49 
141=50 
142=50 
143=50 
144=51 
145=51 
146=52 
147=52 
148=52 
149=53 
150=53 
151=53 
152=54 
153=54 
154=54 
155=55 
156=55 
157=55 
158=56 
159=56 
160=56 
161=57 
162=57 
163=58 
164=58 
165=58 
166=59 
167=59 
168=59 
169=60 
170=60 
171=60 
172=61 
173=61 
174=61 
175=62 
176=62 
177=62 
178=63 
179=63 
180=64 
181=64 
182=64 
183=65 
184=65 
185=65 
186=66 
187=66 
188=66 
189=67 
190=67 
191=67 
192=68 
193=68 
194=68 
195=69 
196=69 
197=70 
198=70 
199=70 
200=71 
201=71 
202=71 
203=72 
204=72 
205=72 
206=73 
207=73 
208=73 
209=74 
210=74 
211=74 
212=75 
213=75 
214=76 
215=76 
216=76 
217=77 
218=77 
219=77 
220=78 
221=78 
222=78 
223=79 
224=79 
225=79 
226=80 
227=80 
228=80 
229=81 
230=81 
231=82 
232=82 
233=82 
234=83 
235=83 
236=83 
237=84 
238=84 
239=84 
240=85 
241=85 
242=85 
243=86 
244=86 
245=86 
246=87 
247=87 
248=88 
249=88 
250=88 
251=89 
252=89 
253=89 
254=90 
255=90

Ok, gonna test it later today or tomorrow, looks indeed good… I ow you a beer!

omg, this is working
thnx so much!! whay do i ow you ? :slight_smile:

1 Like

Nothing, I kinda wanted to know how to do this myself and you forced me to figure it out.

hehe, cool :slight_smile:

Petro, your code is working well, except 1 small issue i think

most brightness levels are working, like 10% , 60% , but if i use 40% nothing happens …
i think my controller doest accept maybe all numbers

can i change the code below, so it is always rounded to 10 20 30 40 … 90
so if brightness is for example : 40% => so (102/255) * 90 = 36 => rounded to below = 30
so if brightness is for example : 80% => so (204/255) * 90 = 72 => rounded to below = 70

{{ '%02.f'%((states('input_number.dimmer1') | float / 255 ) * 90) }}

or maybe another approach, but back the sliders to 0 - 90 , steps 10, instead of 0 - 255

then change the formula in code below ? like ?
value: "{{ (brightness / 255) * 90}}"

  set_level:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.dimmer1
        value: "{{ brightness }}"

The slider has to be 0-255 to mimic a light slider.

Try this equation:

{{ '%02.f'%((((states('input_number.dimmer1') | float / 255 ) * 90) // 10) * 10) }}

it essentially rounds your number every 10% of the bar with only the very top number being 90.

This equation rounds so that first and last 5% of the are zero, and full brightness. Everything between is in 10% increments.

{{ '%02.f'%(((((states('input_number.dimmer1') | float / 255 ) * 90) / 10 ) | round(0) ) * 10) }}

ok, you are my hero :slightly_smiling_face:

tried the first one, and working perfect now

I’m in a similar boat:

input_number:
  soundbar_volume:
    name: Soundbar Volume
    min: 70
    max: 100
    icon: mdi:volume-high

I need to create a template light that controls this. Any help? Thanks.