Sensor value as parameter

Hello,

I am trying to setup a script that adds an alarm to my squeezebox/lms player.

Here is the current script:

alarm:
  alias: alarm
  sequence:
    - service: media_player.squeezebox_call_method
      data:
        entity_id: media_player.picoreplayer
        command: alarm
        parameters: ["add", "enabled:1", "url:http://digitacdn.master.m3u8", "time:9000"]

The script is working but I would like to add the time with two slider (hours and minutes) instead of it being hardcoded. (Time is the last parameter) I have created the sliders (and sensors) for hours and minutes. The time needs to be formatted as seconds from midnight.

So the sensor values needs to be formatted to seconds. Maybe something like this:

Sensor.hours x 60 x 60 + Sensor.minutes x 60

Could somebody help me how to create template or something that would do the trick. And provide an example on how to add it correctly to the parameters.

Thank you very much!

Update.

Now I have these two sensors:

      lms_alarm_hours:     
        friendly_name: 'Hours to seconds'
        value_template: '{{ states("input_number.alarmhour") | int * 3600 }}'    
      lms_alarm_minutes:
        friendly_name: 'Minutes to seconds'
        value_template: '{{ states("input_number.alarmmins") | int * 60 }}' 

How can I combine these.

eg:

      lms_alarm_all:
        friendly_name: 'All'
        value_template: '{{ states("sensor.lms_alarm_hours.state") + states("sensor.lms_alarm_minutes.state") | round(0) }}' 

This one is not working

States are strings, if you want to add them you have to make them numbers by applying the integer or float filters:

value_template: "{{ states('sensor.lms_alarm_hours')|int + states('sensor.lms_alarm_minutes')|int }}"

As they are now integers there is no need for the round() filter.

Also there is no need for .state at the end of your entity_ids when using the states() format.

See the templating documents: https://www.home-assistant.io/docs/configuration/templating/#states

1 Like

Here’s an example of how I solved your problem.
First add a time sensor if you don’t already have it.

sensor:
  - platform: time_date
    display_options:
      - 'time'

Then add an input_datetime component to hold the time you will be inputting. Here I’m adding a datetime for archiving my system.

input_datetime:
  system_archive:
    has_date: false
    has_time: true

Next your automation for what you want the system to do when the time occurs. Obviously you don’t need the extra condition.

automation:
  - alias: 'System Archive'
    trigger:
      platform: template
      value_template: >
        {{ states('sensor.time')
          == (states.input_datetime.system_archive.attributes.timestamp
            | int | timestamp_custom('%H:%M', False)) }}
    condition:
      condition: time
      weekday:
        - wed
        - sun
    action:
      - service: script.hassio_archive

Finally add your setting control to the UI. This will provide a nicely formatted input box that you can type your time into. This example also displays the current time in a separate UI control which is not necessary.

      - type: entities
        title: HA Application
        show_header_toggle: false
        entities:
          - entity: sensor.time
            name: Local time
          - entity: input_datetime.system_archive
            name: Archive at

I use similar code for all my system settings of datetime, numbers, etc. Enjoy!

Thank you very much, everything is working now as supposed!

Many years later… :roll_eyes:

Have this ever been don ethe other way around?

I.e. set alarm on the squeezebox (my case Radio) and have Homeassistant automations/scripts triggered?

I really appreciate Homeassistant, but I don’t want to teach my kids, wife to remember to set alarms there. And least thing I want to do is to open phone/computer 30s before bedtime.
So I want to set alarms on my Logitech Squeezebox radio and have additional (e.g. wake-up lights) triggered based of the alarm time set on the radio.

Anyone done this already?

Hi,

I have exactly the same will of integration but cannot find how to recover the alarm infos on HA so that it can trigger events.
Have you found a way?
Thx