Hi everyone,
Is there a way to apply to a device position, a templace calculation ?
For example, for a shelly module action:
- device_id: d98f855e3e1244c381999999bdfa
domain: cover
entity_id: cover.shellyswitch25_98cd99999cc
type: set_position
position: '{{ 1 / states('sensor.ble_illuminance_582d3460cd93')| float ** 0.7 * 20000 | int}} '
Position seem only to work with integer (between 0 to 100 ?)
Is there a workaround for this usage type ?
You’ll have to explain what you are trying to calculate with your template…
but you can use templates to define the position value if you use a Call service action instead of a Device action.
action:
- service: cover.set_cover_position
target:
entity_id: cover.shellyswitch25_98cd99999cc
data:
position: >
{{ 1 / states('sensor.ble_illuminance_582d3460cd93')| float ** 0.7 * 20000 | int}}
Hello @Didgeridrew
Indeed, I need to explain^^
I want to shut my rolling shutter regarding outdoor luminosity.
I was “reverse” a function to have a non linear level value regarding the lux number (wired idea)
Globally, value is
- near 10% when lux is > 10000
- near 100% when lux ~ 1000
I didn’t want a linear function because I don’t want to be at 50% when lux ~5000.
I will try your solution to fix position with template, thanks.
Do you have another suggestion for roller shutter “step” closing regarding lux ?
For an automation, I would probably use this as the base for a template sensor.
I’ve used a geometric-ish sequence in this example, but you can play around with the values in the map to get the shading that you like:
template:
- sensor:
- name: "Illuminance Position"
state: >
{% set lux =
( states('sensor.ble_illuminance_582d3460cd93')
| float(0) | round(-3, "floor")) | int %}
{%- if lux > 10000 %}{% set lux = 10000 %}
{% elif lux < 1000 %}{%- set lux = 0 %}
{% endif %}
{%- set map = {
0: 0,
1000: 0.8,
2000: 0.12,
3000: 0.17,
4000: 0.22,
5000: 0.28,
6000: 0.36,
7000: 0.46,
8000: 0.60,
9000: 0.77,
10000: 1 } %}
{{ map.get(lux)}}
alias: "Adjust Blinds - Illuminance"
description: >
Adjust the position of the blinds based on the illuminance position sensors value
trigger:
- platform: state
entity_id: sensor.illuminance_position
not_from:
- "unknown"
- "unavailable"
for: '00:01:00'
condition: []
action:
- service: cover.set_cover_position
target:
entity_id: cover.shellyswitch25_98cd99999cc
data:
position: "{{ trigger.to_state.state }}"
mode: single