[SOLVED] First stab at Jython

OK I needed to add the area triggers pieces. My initial testing of the papillon light & motion look good now.

Programming wise you guys are far beyond me. I am just a network & systems administrator who uses programming to automate asks and simplify management.
Thank you very much @5iver

1 Like

Awesome! You’re the first confirmed user of area triggers!!!

Not in production yet, but getting closer

Old men move s-l-o-w. (almost 65)

This thread is morphing a bit and that is OK. We are mixing Time of Day & triggers. Here are some observations & suggestions, not criticisms.

Triggers should have an option where the Mode IS the trigger. That is what is needed for one of my situations. I have some ideas for workarounds. The “always on” Switch keeps the lights on because there is no trigger to turn them off.

I see situations where you may want multiple Mode dictionaries for ToD to handle different situations. There is also a scalability issue, if I understand your metadata correctly. If you with to add a new mode, you need to adjust ALL your metadata rules to account for it.
It may also be useful to have a particular mode that could be time-adjusted from the UI.

One really bad thing with this automation is that the log rule names do not correspond to the text files unless you can refer back to when the file was first loaded.

If you are going to use area triggers, we could just move over to that topic?

When an area becomes active, the actions is executed based on the current Mode. When the Mode changes, the actions are executed again for each active area, based on the new Mode. Modes don’t trigger areas. If you tell me the scenario, I’ll will provide an example.

If you set the brightness to 0 for a Mode, the light will turn off, like in the christmas_light example
 is that what you are missing? The area stays active, due to the manual switch trigger, but the mode changes and adjusts the lights. If the manual trigger is turned off, the area is never active and the light will never turn on.

I need more specifics.

You would start by adding the Mode to the configuration.mode_dict. Then, add an entry for the new Mode in configuration.area_triggers_and_actions_dict[“default_levels”]. Last, update your metadata script to include the Mode for any areas that need to be handled differently than the values in default_levels.

OH3

I’m not sure what you mean. The names of the module and function, or rule, are used in the logger


However, the logging can always look better!

OK, these lights stay ON after the switch is moved to ON. They do not turn off when the mode changes.

What do you have in the log at the time of the Mode change?

Note: The last line it where I turned 1 plug off manually to kill the light

2019-10-23 20:27:07.322 [ome.event.ItemUpdatedEvent] - Item 'outside_trigger' has been updated.

2019-10-23 20:27:13.510 [ome.event.ItemCommandEvent] - Item 'outside_trigger' received command ON

2019-10-23 20:27:13.513 [GroupItemStateChangedEvent] - gOutside_Trigger changed from NULL to ON through outside_trigger

2019-10-23 20:27:13.513 [vent.ItemStateChangedEvent] - outside_trigger changed from NULL to ON

2019-10-23 20:27:13.514 [.event.RuleStatusInfoEvent] - dfb9d0c9-e4e7-4489-aa5f-2537c044d8d8 updated: RUNNING

2019-10-23 20:27:13.531 [ome.event.ItemCommandEvent] - Item 'plug_001' received command ON

2019-10-23 20:27:13.548 [nt.ItemStatePredictedEvent] - plug_001 predicted to become ON

2019-10-23 20:27:13.553 [vent.ItemStateChangedEvent] - plug_001 changed from OFF to ON

2019-10-23 20:27:13.556 [ome.event.ItemCommandEvent] - Item 'plug_002' received command ON

2019-10-23 20:27:13.569 [nt.ItemStatePredictedEvent] - plug_002 predicted to become ON

2019-10-23 20:27:13.576 [ome.event.ItemCommandEvent] - Item 'plug_003' received command ON

2019-10-23 20:27:13.582 [vent.ItemStateChangedEvent] - plug_002 changed from OFF to ON

2019-10-23 20:27:13.583 [.event.RuleStatusInfoEvent] - dfb9d0c9-e4e7-4489-aa5f-2537c044d8d8 updated: IDLE

2019-10-23 20:27:13.583 [nt.ItemStatePredictedEvent] - plug_003 predicted to become ON

2019-10-23 20:27:13.589 [vent.ItemStateChangedEvent] - plug_003 changed from OFF to ON

2019-10-23 21:30:00.397 [.event.RuleStatusInfoEvent] - e2f41d7d-6558-42de-90ef-69acb98e2647 updated: RUNNING

2019-10-23 21:30:00.400 [ome.event.ItemCommandEvent] - Item 'Mode' received command Night

2019-10-23 21:30:00.401 [.event.RuleStatusInfoEvent] - e2f41d7d-6558-42de-90ef-69acb98e2647 updated: IDLE

2019-10-23 21:30:00.404 [vent.ItemStateChangedEvent] - Mode changed from Evening to Night

2019-10-23 23:42:29.639 [vent.ItemStateChangedEvent] - plug_001 changed from ON to OFF

This is the event.log, which can be useful, but logging from the helper libraries and rules will be in the openhab.log. When someone asks for a log file, most of the time they are asking for openhab.log.

Sorry, I grabbed that from Frontail which pulls both, I thought.

Nothing really in openhab log.

2019-10-23 20:19:11.529 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/community/area_triggers.py'
2019-10-23 20:27:07.317 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'plug.items'

Did you perform steps 2 and 3?

https://openhab-scripters.github.io/openhab-helper-libraries/Getting%20Started/Installation.html

I did but there were instructions after the successful hello world to dial that back.

openhab> log:list | grep auto
org.openhab.core.automation                        x WARN
openhab> log:list | grep jsr2
jsr223                                             x WARN
openhab>

EDIT: I just set automation to debug.

Automation is something that you could turn off, but jsr223 should stay at debug. For now, set them both to debug.

2019-10-24 07:34:00.006 [.event.RuleStatusInfoEvent] - e2f41d7d-6558-42de-90ef-69acb98e2647 updated: RUNNING

2019-10-24 07:34:00.007 [ome.event.ItemCommandEvent] - Item 'Mode' received command Day

2019-10-24 07:34:00.007 [.event.RuleStatusInfoEvent] - e2f41d7d-6558-42de-90ef-69acb98e2647 updated: IDLE

2019-10-24 07:34:00.009 [vent.ItemStateChangedEvent] - Mode changed from Morning to Day

Ah, OK
 that’s in the event.log
 nothing I can do about it in the helper libraries.

Also in the other log.

2019-10-24 19:08:59.753 [DEBUG] [e.automation.internal.RuleEngineImpl] - The trigger 'Item-gOutside_Trigger-changed_e93e40def5f311e992404da28a0d7975_e93e67f0f5f311e9bf0f4da28a0d7975' of rule 'dfb9d0c9-e4e7-4489-aa5f-2537c044d8d8' is triggered.
2019-10-24 19:08:59.764 [DEBUG] [jsr223.jython.Area triggers         ] - gOutside_Trigger: [OFF]
2019-10-24 19:08:59.772 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_001], namespace [area_triggers_and_actions], args [('actions',)]
2019-10-24 19:08:59.774 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_001], namespace [area_triggers_and_actions]
2019-10-24 19:08:59.775 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_001], namespace [area_triggers_and_actions], args [('actions', 'light_action')]
2019-10-24 19:08:59.776 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_001], namespace [area_triggers_and_actions]
2019-10-24 19:08:59.778 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_001], namespace [area_triggers_and_actions], args [('modes', 'Evening')]
2019-10-24 19:08:59.779 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_001], namespace [area_triggers_and_actions]
2019-10-24 19:08:59.781 [DEBUG] [ea_triggers_and_actions.area_actions] - [plug_001]: switch is already set to [OFF], so not sending command
2019-10-24 19:08:59.782 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_002], namespace [area_triggers_and_actions], args [('actions',)]
2019-10-24 19:08:59.784 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_002], namespace [area_triggers_and_actions]
2019-10-24 19:08:59.785 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_002], namespace [area_triggers_and_actions], args [('actions', 'light_action')]
2019-10-24 19:08:59.787 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_002], namespace [area_triggers_and_actions]
2019-10-24 19:08:59.788 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_002], namespace [area_triggers_and_actions], args [('modes', 'Evening')]
2019-10-24 19:08:59.789 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_002], namespace [area_triggers_and_actions]
2019-10-24 19:08:59.791 [DEBUG] [ea_triggers_and_actions.area_actions] - [plug_002]: switch is already set to [OFF], so not sending command
2019-10-24 19:08:59.792 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_003], namespace [area_triggers_and_actions], args [('actions',)]
2019-10-24 19:08:59.793 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_003], namespace [area_triggers_and_actions]
2019-10-24 19:08:59.795 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_003], namespace [area_triggers_and_actions], args [('actions', 'light_action')]
2019-10-24 19:08:59.796 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_003], namespace [area_triggers_and_actions]
2019-10-24 19:08:59.797 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_003], namespace [area_triggers_and_actions], args [('modes', 'Evening')]
2019-10-24 19:08:59.799 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_003], namespace [area_triggers_and_actions]
2019-10-24 19:08:59.800 [DEBUG] [ea_triggers_and_actions.area_actions] - [plug_003]: switch is already set to [OFF], so not sending command
2019-10-24 19:08:59.801 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [gOutside_Trigger], namespace [area_triggers_and_actions], args [('actions',)]
2019-10-24 19:08:59.806 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [gOutside_Trigger], namespace [area_triggers_and_actions]
2019-10-24 19:08:59.807 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule 'dfb9d0c9-e4e7-4489-aa5f-2537c044d8d8' is executed.
2019-10-24 19:09:01.446 [DEBUG] [e.automation.internal.RuleEngineImpl] - The trigger 'Item-gOutside_Trigger-changed_e93e40def5f311e992404da28a0d7975_e93e67f0f5f311e9bf0f4da28a0d7975' of rule 'dfb9d0c9-e4e7-4489-aa5f-2537c044d8d8' is triggered.
2019-10-24 19:09:01.448 [DEBUG] [jsr223.jython.Area triggers         ] - gOutside_Trigger: [ON]
2019-10-24 19:09:01.450 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_001], namespace [area_triggers_and_actions], args [('actions',)]
2019-10-24 19:09:01.451 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_001], namespace [area_triggers_and_actions]
2019-10-24 19:09:01.453 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_001], namespace [area_triggers_and_actions], args [('actions', 'light_action')]
2019-10-24 19:09:01.455 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_001], namespace [area_triggers_and_actions]
2019-10-24 19:09:01.456 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_001], namespace [area_triggers_and_actions], args [('modes', 'Evening')]
2019-10-24 19:09:01.460 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_001], namespace [area_triggers_and_actions]
2019-10-24 19:09:01.464 [INFO ] [ea_triggers_and_actions.area_actions] - >>>>>>> plug_001: ON
2019-10-24 19:09:01.466 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_002], namespace [area_triggers_and_actions], args [('actions',)]
2019-10-24 19:09:01.470 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_002], namespace [area_triggers_and_actions]
2019-10-24 19:09:01.474 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_002], namespace [area_triggers_and_actions], args [('actions', 'light_action')]
2019-10-24 19:09:01.476 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_002], namespace [area_triggers_and_actions]
2019-10-24 19:09:01.478 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_002], namespace [area_triggers_and_actions], args [('modes', 'Evening')]
2019-10-24 19:09:01.483 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_002], namespace [area_triggers_and_actions]
2019-10-24 19:09:01.486 [INFO ] [ea_triggers_and_actions.area_actions] - >>>>>>> plug_002: ON
2019-10-24 19:09:01.489 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_003], namespace [area_triggers_and_actions], args [('actions',)]
2019-10-24 19:09:01.490 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_003], namespace [area_triggers_and_actions]
2019-10-24 19:09:01.492 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_003], namespace [area_triggers_and_actions], args [('actions', 'light_action')]
2019-10-24 19:09:01.494 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_003], namespace [area_triggers_and_actions]
2019-10-24 19:09:01.496 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [plug_003], namespace [area_triggers_and_actions], args [('modes', 'Evening')]
2019-10-24 19:09:01.499 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [plug_003], namespace [area_triggers_and_actions]
2019-10-24 19:09:01.510 [INFO ] [ea_triggers_and_actions.area_actions] - >>>>>>> plug_003: ON
2019-10-24 19:09:01.513 [DEBUG] [jsr223.jython.core.metadata         ] - get_key_value: Item [gOutside_Trigger], namespace [area_triggers_and_actions], args [('actions',)]
2019-10-24 19:09:01.515 [DEBUG] [jsr223.jython.core.metadata         ] - get_metadata: Item [gOutside_Trigger], namespace [area_triggers_and_actions]
2019-10-24 19:09:01.553 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule 'dfb9d0c9-e4e7-4489-aa5f-2537c044d8d8' is executed.

There’s something that will help people
 set jsr223.jython.core to INFO. I need to get that into the docs.

Like this?

openhab> log:list | grep jsr2
jsr223                                             x DEBUG
openhab> log:set INFO jsr223
openhab> log:list | grep jsr2
jsr223                                             x INFO
openhab>

log:set INFO jsr223.jython.core

OK & I set jsr223 back to DEBUG