Help with Dimming Automation

Hey All,

Slowly getting to grips with hass and it’s somewhat fantastic abilities! Really enjoying programming and thinking through all the automations I can do with this and my devices.

I am trying to think this through in terms of building a template and I hope someone can help point me in the right direction for!

So - I have a terrarium (turtle tank) which has a dimmer controlled light for the basking area - with a 1-wire temp sensor to read the temperature. I used to manage this with a Pi, however now plan to integrate this into hass. I have swapped the Pi out for an esp8266 and MQTT to hass.

So I get the temperature into hass as sensor.turtle_temperature. The next step, would be to have hass brighten / dim the socket (light.turtle_bask_dimmer) to regulate the temperature.

So far - have put this together:

- alias: Brighten turtle lamp
    - platform: numeric_state
      entity_id: sensor.turtle_temperature
      below: 26
    - condition: state
      entity_id: light.turtle_bask_dimmer
      state: 'on'
    - service: homeassistant.turn_on
      entity_id: light.turtle_bask_dimmer

Now what I want to do, is brighten the lamp by 50% (up to a maximum of 255). So if the lamp is currently at 128, increase the brightness to 192 then delay 1 minute.

I’ll also create another automation for dimming the lamp if the temperature exceed 28c.

The piece is the template / math I need to increase the brightness, and how to read the current value to work against. I have a feeling I might need to invoke a script instead?

Thanks in advance!

I don’t have an answer, so much as a direction to head. To use templates with your brightness, you need to use data_template:

    - service: homeassistant.turn_on
      entity_id: light.turtle_bask_dimmer
        brightness: '{{ states.light.turtle_bask_dimmer.attributes.brightness | multiply(1.5) | float  }}'

That “float” filter might not be needed… When you’re debugging, the template dev tool (icon in the HASS sidebar) is super-helpful. You’ll want to work in some if/then logic to set.

And I’m not sure that multiplying by 1.5 is really what you want. Note that you could use
{{ (states.light.turtle_bask_dimmer.attributes.brightness * 1.5) }}
I just wanted to show that you can stack filters.

Also - when you’re ready for it - the attributes of triggers are available to templates.

That’s a great start! Thanks - I’ll take a look at that and see how it goes!