How to set max value?

I have this template to raise or low the volume of a media_player:

- service: media_player.volume_set
  data_template:
    entity_id: media_player.salotto_audio
    volume_level: >
      {% if trigger.event.data.action_value | float > 0 %}
        {{  states.media_player.salotto_audio.attributes.volume_level | float + 0.5 }}
      {% else %}
        {{  states.media_player.salotto_audio.attributes.volume_level | float - 0.5 }}
      {% endif %}

And i get this error:

2018-11-16 11:40:39 ERROR (MainThread) [homeassistant.core] Invalid service data for media_player.volume_set: value must be at most 1 for dictionary value @ data['volume_level']. Got '1.050000011920929'

How to set a max value in that template?

:joy::rofl: i can’t descently explain you how to sex :joy::rofl:

===> ok, i go out :grin:

- service: media_player.volume_set
  data_template:
    entity_id: media_player.salotto_audio
    volume_level: >
      {% set vol = state_attr('media_player.salotto_audio', 'volume_level')|float %}
      {% if trigger.event.data.action_value|float > 0 %}
        {{ (vol + 0.5, 1.0)|min }}
      {% else %}
        {{ (vol - 0.5, 0.0)|max }}
      {% endif %}

Thanks… i will try this…