- sim800l.send_sms within lambda?

Hi. This works outside a lambda:

          - sim800l.send_sms:
              recipient: "+xxxxxxxxxxx"
              message: UKNOWN COMMAND sent to septic tank alarm system!

Any ideas how I do this inside a lambda… (my version here does not work…)

sim800l:
  on_sms_received:
    - lambda: |-
        id(sms_sender).publish_state(sender);
        id(sms_message).publish_state(message);  
        if (message == "alarm-off" || message == "Alarm-off" || message == "alarm off" || message == "Alarm off" ){
           id(alarm_piezio_relay).turn_off(); 
           auto call = id(alarm_led).turn_off();
           call.perform();
        }    
        else{
          - sim800l.send_sms:
              recipient: "+xxxxxxxxxxxx"
              message: UKNOWN COMMAND sent to septic tank alarm system!
        }

You’re mixing lambda and yaml - this won’t work.

Have a look at the if Action in the documentation, you can still use lambda in the condition (again that’s in the doco, just above if Action).

You could also possibly put your send sms action in a script, then call that script from lambda. I haven’t tried this though so not sure how well it works.

id(your_script_name).execute();
2 Likes

Thank you - using a script worked great :slight_smile:

This is a good general technique I’ve never thought about.

Sometimes “the lambda way” is hard to find or even undocumented, and this method of calling a script helps you bridge that. Nice one.