Reference Email Address and Other Text in a Blockly Alert Rule?

I manage a number of system that we use for monitoring and automation. For the monitoring, I have rules with email and/or text alerts which I have created using Blockly. I am interested to know if there is a way for all of these rules to reference an email address (in the “to” block), and a house name (in the “with subject” block) so I don’t have to go enter these in each alert rule manually when I build these systems.

Here is what the blocks look like:

You have two options.

  1. Put them into Items.

  2. Put them into the shared cache

The advantage of putting them into Items is the Item can be modified from the UI and gets restored on startup if configured. For 2 you’ll need a system startup rule that restores them to cache.

Option 3)
Create a dedicated script only for sending the message. From the rule you only call the script with the necessary parameters and have everything else configured within the script itself

Option 4)
Create your own blockly

Thanks, I don’t understand how to implement any of these options.

rikoshak how would I create an item, say for the email address? Then I would just plug the item in where the email address is in this script? I tried creating an item with the ID of my email but it wouldn’t accept the special @ character it seems.

From the Items page click the + to add a new Item. Set the type as a String. Use an Input widget to populate it.

No, you need to get the state of the Item.

You might benefit from reviewing/rereviewing the Getting Started tutorial.

Wow I’m completely overwhelmed. Widgets are new to me so “Use an Input widget to populate it.” is certainly the part I need.

If I understand what this does, it creates a “state” for this item right? So where the state of one of my temperature items may be “70”, through this widget, the state of this “Email Address” Item I created would be myemailaddress@gmail.com. Then I can get my rule to pull that item state to use for where the email is going. Does that sound right?

If so, it looks like I create the Item, save it, click on metadata, Default List Item Widget, then choose input list item.

This gets me to the editing table for the input widget (if I’m saying that right). But there are a bunch of parameters that are completely unclear to me. And I DO see the same line items in the instructions, but they are equally confusing to me. If I click on the “F7 Input Docs” link to determine what kind of input I should enter it leads me to a web page with TONS of complex code for doing things way more complicated than I need.

In that edit form, it must be a couple of really simple entries that result in the state of the Item to be the email address I want?

Thanks for your help.

Mostly right and it may just be language choice. But it’s important to be absolutely correct and understand these because these are really very basic openHAB concepts which you should have a handle on before attempting to write rules. If you don’t understand the information in the Concepts section of the OH docs you will have a hard time with openHAB. And what Items are and how they work is perhaps the most important concept in OH.

Just diving in without reviewing at least the Concepts and the Getting Started tutorial is a recipe for frustration and much waisted time.

To answer this question, the widget doesn’t create a state for the Item per se. It provides a UI element on MainUI that allows you to change the state of the Item manually by typing in the value. This is not the only way to set the state of an Item.

And yes, your rule will use the state of the Item in the rule (there’s a “get X from Item” block).

All you really need is in that very first line of the docs that it links to.

All text inputs Supported types: text, password, email, tel, url, date, number, datetime-local

You want an email address so put in email for the Input type.

I’m still getting NULL as the state. I tried with an email address in the Name box and email in the type box, in teh mode box, and in both:

This is how the process works.

  1. Create an Item
    a. Type String
    b. Add it to the Sematic Model so it shows up in the Overview Page
  2. Add a “default list item widget”
  3. Choose an “Input List Item”
    a. put “email” into the Input Type field
    b. optional: toggle on “Send button”
    c. optional: toggle on “Show outline”
    d. optional: toggle on “Validate”
    e. save
  4. Navigate to the Overview Page and choose the Locations tab and open the card where the Item created in 1
  5. Enter the email address and click the check mark (if “Send button” was turned on)

To change the email in the future, repeat steps 4 and 5.

Alternatively you can:

  1. Create an Item
    a. Type String
    b. It doesn’t matter if you add it to the semantic model or not
  2. Add a “default stand alone widget”
  3. Choose an “Input Card”
    a. put “email” into the Input Type field
    b. optional: toggle on “Send button”
    c. optional: toggle on “Show outline”
    d. optional: toggle on “Validate”
    e. save
  4. At the top of the Item’s page it will now show this stand alone widget.
  5. Enter the email address and click the check mark (if “Send button” was turned on)

To change the email in the future, navigate to the Item’s page and repeat step 5 above. Or you can add this stand alone widget to a Page.

Nothing gets sent to the Item until you actually use the widget.

rikoshak despite your very detailed instructions (thanks!) I was still having problems getting it working. But the part about being able to reference an Item label gave me the idea to just create an email address item with the actual email address as the label. Then I use the blockly script to call that Item. This is super simple and seems to work. Is there some reason I shouldn’t use this way of doing this?

image

It’s a little odd but not terrible. But if you can get the label I don’t understand why you can’t get the state. It’s the exact same block, just select “state” instead of “label”.

The biggest limitation is that end users won’t be able to change the email address. Only admin users can change the label of an Item. But end users can change the state of an Item.

It was something about the widget. Couldn’t get it right. As you suggested, I need to learn more about using those.