Here is a widget for moving PTZ cameras. If you can improve on it then please post your changes. It can move a camera that either supports ONVIF presets, Relative movements and now also Continuous move (@Aspergillus thanks for contributing some code).
Steps to get this working:
- You need to either use one of these two features to auto create the items with the default naming.
“Add Equipment to model”
“Create Equipment from thing”
If using textual config, you will need to either edit the widget or create your items to match the standard naming. - Make sure when creating the Equipment you click ‘show advanced’ to see all the channels and tick the Pan, Tilt, Zoom, GoToPreset and
MJPEG URL
channels as a minimum. - Select the Equipment/Item that is your desired camera in the setup of the widget.
- Optionally you can select an item you wish to switch on and off. Example the lights in the room that the camera is in. Alternatively it may be blinds or a motorized gate, the choice is yours and if you leave this blank the control disappears.
- If your camera does not support Relative movements, then you can hide those controls and just use Presets instead. If your camera supports it, you will see a named list of your presets appear that you can choose from that will take your camera directly to the selected preset location.
Thumb nail that when clicked opens up to bigger view.
Setup
Widget Code
uid: ClickablePTZCamera
props:
parameters:
- context: item
label: Select the Camera to Control
name: camera
required: true
type: TEXT
- label: Show Equipment Controls
name: showSettings
required: true
type: BOOLEAN
- label: Show PTZ Controls
name: showControls
required: true
type: BOOLEAN
- label: Show Stop Button
name: showMoveStop
required: true
type: BOOLEAN
- label: Show Preset Locations
name: showPresets
required: true
type: BOOLEAN
- label: Invert Tilt Control
name: invertTilt
required: true
type: BOOLEAN
- label: Invert Pan Control
name: invertPan
required: true
type: BOOLEAN
- label: Show Audio Alarms
name: showAudioAlarms
required: true
type: BOOLEAN
- label: Show Motion Alarms
name: showMotionAlarms
required: true
type: BOOLEAN
- context: item
label: Item for Switch
name: switchItem
required: false
type: TEXT
component: f7-card
config:
class: no-margin
expandable: true
style:
--f7-card-margin-horizontal: 0px
border-radius: 6px
height: 9rem
width: 16rem
slots:
default:
- component: f7-card-content
config:
class: card-opened-fade-out
style:
background-image: ="url('"+items[props.camera + "_MJPEG_URL"].state+"')"
background-repeat: no-repeat
background-size: 17rem 10rem
border-radius: 6px
color: var(--f7-card-header-text-color)
z-index: -1
- component: f7-card-content
config:
class: card-opened-fade-in
style:
background-image: ="url('"+items[props.camera + "_MJPEG_URL"].state+"')"
background-position: center
background-repeat: no-repeat
background-size: 100% auto
color: var(--f7-card-header-text-color)
z-index: -1
- component: oh-link
config:
action: toggle
actionCommand: ON
actionCommandAlt: OFF
actionItem: =props.switchItem
class: card-prevent-open
iconF7: power
iconSize: 22
style:
color: "=(items[props.switchItem].state === 'OFF') ? 'white' : (items[props.switchItem].state === '0,0,0') ? 'white' : (items[props.switchItem].state === '0') ? 'white' : 'cyan'"
margin: 0em 0.2em
opacity: 0.5
visible: =props.switchItem !== undefined
- component: oh-link
config:
action: command
actionCommand: "=(props.invertPan) ? 'DECREASE' : 'INCREASE'"
actionItem: =props.camera + "_Pan"
class: card-prevent-open
iconF7: arrow_left
iconSize: 22
style:
color: var(--f7-card-header-text-color)
margin: 0 0.2em
opacity: 0.5
visible: =props.showControls === true
- component: oh-link
config:
action: command
actionCommand: "=(props.invertTilt) ? 'INCREASE' : 'DECREASE'"
actionItem: =props.camera + "_Tilt"
class:
- card-prevent-open
iconF7: arrow_up
iconSize: 22
style:
color: var(--f7-card-header-text-color)
margin: 0 0.2em
opacity: 0.5
visible: =props.showControls === true
- component: oh-link
config:
action: command
actionCommand: OFF
actionItem: =props.camera + "_Pan"
class:
- card-prevent-open
iconF7: stop_circle
iconSize: 22
style:
color: var(--f7-card-header-text-color)
margin: 0 0.2em
opacity: 0.5
visible: =props.showMoveStop === true
- component: oh-link
config:
action: command
actionCommand: "=(props.invertTilt) ? 'DECREASE' : 'INCREASE'"
actionItem: =props.camera + "_Tilt"
class: card-prevent-open
iconF7: arrow_down
iconSize: 22
style:
color: var(--f7-card-header-text-color)
margin: 0 0.2em
opacity: 0.5
visible: =props.showControls === true
- component: oh-link
config:
action: command
actionCommand: "=(props.invertPan) ? 'INCREASE' : 'DECREASE'"
actionItem: =props.camera + "_Pan"
class: card-prevent-open
iconF7: arrow_right
iconSize: 22
style:
color: var(--f7-card-header-text-color)
margin: 0 0.2em
opacity: 0.5
visible: =props.showControls === true
- component: oh-link
config:
action: command
actionCommand: INCREASE
actionItem: =props.camera + "_Zoom"
class: card-prevent-open
iconF7: plus
iconSize: 22
style:
color: var(--f7-card-header-text-color)
margin: 0 0.2em
opacity: 0.5
visible: =props.showControls === true
- component: oh-link
config:
action: command
actionCommand: DECREASE
actionItem: =props.camera + "_Zoom"
class:
- card-prevent-open
iconF7: minus
iconSize: 22
style:
color: var(--f7-card-header-text-color)
margin: 0 0.2em
opacity: 0.5
visible: =props.showControls === true
- component: oh-link
config:
action: options
actionItem: =props.camera + "_Go_To_Preset"
class: card-prevent-open
iconF7: list_number
iconSize: 22
style:
color: var(--f7-card-header-text-color)
margin: 0 0.2em
opacity: 0.5
visible: =props.showPresets === true
- component: oh-link
config:
action: group
actionGroupPopupItem: =props.camera
class: card-prevent-open
iconF7: gear_alt
iconSize: 22
style:
color: var(--f7-card-header-text-color)
margin: 0 0.2em
opacity: 0.5
visible: =props.showSettings === true
- component: oh-link
config:
iconF7: eye
iconSize: 18
style:
color: var(--f7-card-header-text-color)
opacity: "=(items[props.camera + '_Motion_Alarm'].state === 'ON') ? '0.5' : '0'"
position: absolute
right: 0.2rem
top: 7.8rem
visible: =props.showMotionAlarms === true
- component: oh-link
config:
iconF7: ear
iconSize: 18
style:
color: var(--f7-card-header-text-color)
left: 0rem
opacity: "=(items[props.camera + '_Audio_Alarm'].state === 'ON') ? '0.5' : '0'"
position: absolute
top: 7.7rem
visible: =props.showAudioAlarms === true