Convert "input_number" to a "template light"

hi, my dimmer lights working on IP commands and hex decimal values, i accomplished this by setiting up an input slider in combination with a shell command and a small automation
but seems input_slider is not a component that can be exposed to google asistant, but template light , thats maybe something i can use… , because its exposed as a light
see below my code, so the input slider goes from from 0 to 90 , (not 0 to 100) those are the hex values i send to my IP controller to turn on the lights on a brightness leve ( 0 - 90 )l, so all i need to change or setup is the a template light also, based on the same config, but i dont know how …

here is my code :

shell command:
dimmer1: "curl -k http://ip.php?hex={{ '%02d'|format(states('input_number.dimmer1')|int) }}"  

dimmer1:
  name: Eethoek Raam
  initial: 0
  min: 0
  max: 90
  step: 10

in automation:
- alias: Dimmer1
  initial_state: 'on'
  trigger:
  - entity_id: input_number.dimmer1
    platform: state
  action:
  - service: shell_command.dimmer1

ok, so i just need to have the set_level action, see below

- platform: template
  lights:          
    dimmer1:
      friendly_name: "Eethoek Raam"
      turn_on:
        service: input_number.set_value
        data:
          entity_id: input_number.dimmer1
          value: 90
      turn_off:
        service: input_number.set_value
        data:
          entity_id: input_number.dimmer1  
          value: 0   
      set_level:
        service: input_number.set_value
        data: SOMETHING HERE , A STATE OF THE INPUT SLIDER?

I think you want to try level_template, see example here

still lost, just dont know what to enter there
i have now:

  set_level:
    service: input_number.set_value
    data_template:
      entity_id: input_number.dimmer1  
      brightness: "{{ trigger.to_state.state | int }}"  

i can change brightness, but notthing happens on my input_slider to give the command

- platform: template
  lights:          
    dimmer1:
      friendly_name: "Eethoek Raam"
      turn_on:
        service: input_number.set_value
        data:
          entity_id: input_number.dimmer1
          value: 90
      turn_off:
        service: input_number.set_value
        data:
          entity_id: input_number.dimmer1  
          value: 0   
      set_level:
        service: shell_command.dimmer1

The problem you will have is that you have no way to translate 0-255 to 0-90.

ok, but cant i give a command to the input_number from the ser_level ?

you give a command directly to the shell

i think i need to set the state of the input_number

Na you don’t need to set it, set level is when the slider for the light changes.

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!