Help with automation setup

Hi,

I am trying to use existing alarm PIR sensors to turn on/off lights following the integration of my alarm system to HA using a custom integration code found on github

I ve setup the automation code as follows:


 - id: one

  alias: office light

  description: office light

  trigger:

  - platform: state

    entity_id: sensor.integra_pir_grafio

    to: '[VIOLATED]'

  action:

  - service: light.turn_on

    target:

      entity_id: light.office_light

    data:

      brightness: 255

However, it doesnt work. I can manually run the automation from the GUI but, it doest get triggered when the sensor is activated. I suspect the problem is with the change

to :[violated]

There is a sensor created for each of the alarms zones which shows as " [] " or as “[violated]” when active.

Can anyone help with this ?

Go to Developer Tools, select the tab State and then search for sensor.integra_pir_grafio. Record the state exactly as it is (case sensitive). If possible to force the violated situation, do that and see the results on this tab.

Thanks for your message.

This is what it looks like (zone not activated)

Its just two brackets
when activated it appears as
[‘VIOLATED’]

So please try this:

- id: one
  alias: office light
  description: office light
  trigger:
  - platform: state
    entity_id: sensor.integra_pir_grafio
    to: "['VIOLATED']"
  action:
  - service: light.turn_on
    target:
      entity_id: light.office_light
    data:
      brightness: 255

It looks like it try to return a list, so you probably will have other possible results to this sensor including some case where ‘VIOLATED’ is one of multiple simultaneous results.
If that is the case, you probably will have more precise results using a template trigger.
Something like this (not tested):

- id: one
  alias: office light
  description: office light
  trigger:
  - platform: template
    value_template: "{{ 'VIOLATED' in states('sensor.integra_pir_grafio') | default([]) }}"
  action:
  - service: light.turn_on
    target:
      entity_id: light.office_light
    data:
      brightness: 255

I will try that thanks!
And yes, there other options to the states besides VIOLATED like TAMPERED, ALARMED, BYPASSED but those dont happen during normal operation

PS: I ve only beem using HA for a couple of weeks now and I find it hard to find good documentation regarding YAML language. I find whats included in the HA docs insufficient. Are there any other online sources ?

I still believe this forum is the best place to learn… and don’t be shy to ask questions here.
But Home Assistant is based on Python and uses Jinja a lot… Apart of the Home Assistant docs, there are plenty of docs for those platforms everywhere. Google will help a lot.

Well comparing my learning curve here with the one I had with arduino and C programming, this one is more steep! Forums are there to mainly to solve problems and they shouldn’t substitute documentation.

Be the way your input has helped alot and it now works both for ON and OFF.
How do I now add a time delay for the lights to stay on after the sensor de-acivates?
I just modified the motion sensor blueprint to also take values from my alarm sensors and it works!

YAML is a Markup Language that is used by a lot of systems. (“YAML Language” is redundant: “Yet Another Markup Language Language”).

So documentation of YAML is very use-specific. Since most of us will never be using YAML in another system other than Home Assistant, then your best place to learn to use YAML is here on the Home Assistant forums.

Fortunately there are some users here who are well-versed in all things YAML. Without their help I could never have graduated from “YAML Illiterate” to “YAML Challenged”. ("YAML Challenged means that any answer I provide has a 50-50 chance of being wrong).

One thing I have learned is that you will never be traumatized by asking a YAML question here.

About the HA Docs:
You have to remember that the docs are written by the developer community who all speak in YAML. Once you understand the basic structure of YAML in Home Assistant the docs will make a little more sense. (Very little). Fortunately many of the developers are active on the forum.

I am always learning. For example just yesterday I learned what the error: “expected dict for dictionary value” means. And I have been struggling with YAML for two years. (So, THAT is what a dict is!).

Over he past two years, the UI has been getting the average user more away from YAML files. Making my life easier. (My first configuration.yaml file was hundreds of lines long).

So, in other words, the only way to learn here is to ask as opposed to RTFM *! :slight_smile:

Try RTFM first. If it still doesn’t work, post your question here showing what you have tried. (Please use code tags).

Odds are good that someone else has previously stumbled through your exact same question before.

1 Like

Following up my ALARM integration in HA, i am now trying to show indication of motion sensor state in a floor plan like this:

 - type: state-icon
    entity: sensor.integra_pir_grafio
    icon: mdi:run
    style:
      top: 40%
      left: 74%
      value_template: '{{ ''VIOLATED'' in states(''sensor.integra_pir_grafio'') | default([]) }}'
      action:
      '--iron-icon-stroke-color': '#8c1414'
      border-radius: 50%
      text-align: center
      background-color: rgba(255, 255, 255, 0.3)

So the icon should change color when sensor state turns to violated but… its doesn’t work.
What am I doing wrong?